diff --git a/CHANGELOG.md b/CHANGELOG.md index f9bf64a1..bcb84d81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Bump `@graphiql/plugin-explorer` version to `^1` +- Ignore fields that represent foreign keys in GraphQL schema generation - When compiling to GraphQL using the CDS API or CLI, only generate GraphQL schemas for services that are annotated with GraphQL protocol annotations ### Fixed diff --git a/lib/schema/util/index.js b/lib/schema/util/index.js index f229ebcf..3331ed63 100644 --- a/lib/schema/util/index.js +++ b/lib/schema/util/index.js @@ -3,9 +3,13 @@ const hasScalarFields = entity => ([, el]) => !(shouldElementBeIgnored(el) || el.isAssociation || el.isComposition) ) +const _isFlatForeignKey = element => Boolean(element['@odata.foreignKey4'] || element._foreignKey4) + const _isLocalized = element => element.name === 'localized' && element.target?.endsWith('.texts') -const shouldElementBeIgnored = element => element.name.startsWith('up_') || _isLocalized(element) +// TODO: add check for @cds.api.ignore +const shouldElementBeIgnored = element => + element.name.startsWith('up_') || _isLocalized(element) || _isFlatForeignKey(element) const isCompositionOfAspect = entity => Object.values(entity.elements.up_?._target.elements ?? {}).some(e => e.targetAspect && e._target.name === entity.name) diff --git a/test/schemas/bookshop-graphql.gql b/test/schemas/bookshop-graphql.gql index 1c9253cf..ec3dc211 100644 --- a/test/schemas/bookshop-graphql.gql +++ b/test/schemas/bookshop-graphql.gql @@ -105,7 +105,6 @@ See https://cap.cloud.sap/docs/cds/common#aspect-managed type AdminService_Books { ID: Int author: AdminService_Authors - author_ID: Int chapters(filter: [AdminService_Chapters_filter], orderBy: [AdminService_Chapters_orderBy], skip: Int, top: Int): AdminService_Chapters_connection createdAt: Timestamp @@ -118,10 +117,8 @@ type AdminService_Books { See https://cap.cloud.sap/docs/cds/common#type-currency """ currency: AdminService_Currencies - currency_code: String descr: String genre: AdminService_Genres - genre_ID: Int image: Binary modifiedAt: Timestamp @@ -136,15 +133,12 @@ type AdminService_Books { input AdminService_Books_C { ID: Int author: AdminService_Authors_C - author_ID: Int chapters: [AdminService_Chapters_C] createdAt: Timestamp createdBy: String currency: AdminService_Currencies_C - currency_code: String descr: String genre: AdminService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp modifiedBy: String @@ -156,15 +150,12 @@ input AdminService_Books_C { input AdminService_Books_U { author: AdminService_Authors_C - author_ID: Int chapters: [AdminService_Chapters_C] createdAt: Timestamp createdBy: String currency: AdminService_Currencies_C - currency_code: String descr: String genre: AdminService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp modifiedBy: String @@ -181,12 +172,9 @@ type AdminService_Books_connection { input AdminService_Books_filter { ID: [Int_filter] - author_ID: [Int_filter] createdAt: [Timestamp_filter] createdBy: [String_filter] - currency_code: [String_filter] descr: [String_filter] - genre_ID: [Int_filter] image: [Binary_filter] modifiedAt: [Timestamp_filter] modifiedBy: [String_filter] @@ -203,12 +191,9 @@ type AdminService_Books_input { input AdminService_Books_orderBy { ID: SortDirection - author_ID: SortDirection createdAt: SortDirection createdBy: SortDirection - currency_code: SortDirection descr: SortDirection - genre_ID: SortDirection image: SortDirection modifiedAt: SortDirection modifiedBy: SortDirection @@ -266,7 +251,6 @@ input AdminService_Books_texts_orderBy { """A Chapter of a Book""" type AdminService_Chapters { book: AdminService_Books - book_ID: Int createdAt: Timestamp """Canonical user ID""" @@ -281,7 +265,6 @@ type AdminService_Chapters { input AdminService_Chapters_C { book: AdminService_Books_C - book_ID: Int createdAt: Timestamp createdBy: String modifiedAt: Timestamp @@ -304,7 +287,6 @@ type AdminService_Chapters_connection { } input AdminService_Chapters_filter { - book_ID: [Int_filter] createdAt: [Timestamp_filter] createdBy: [String_filter] modifiedAt: [Timestamp_filter] @@ -320,7 +302,6 @@ type AdminService_Chapters_input { } input AdminService_Chapters_orderBy { - book_ID: SortDirection createdAt: SortDirection createdBy: SortDirection modifiedAt: SortDirection @@ -440,7 +421,6 @@ type AdminService_Genres { descr: String name: String parent: AdminService_Genres - parent_ID: Int texts(filter: [AdminService_Genres_texts_filter], orderBy: [AdminService_Genres_texts_orderBy], skip: Int, top: Int): AdminService_Genres_texts_connection } @@ -450,7 +430,6 @@ input AdminService_Genres_C { descr: String name: String parent: AdminService_Genres_C - parent_ID: Int texts: [AdminService_Genres_texts_C] } @@ -459,7 +438,6 @@ input AdminService_Genres_U { descr: String name: String parent: AdminService_Genres_C - parent_ID: Int texts: [AdminService_Genres_texts_C] } @@ -472,7 +450,6 @@ input AdminService_Genres_filter { ID: [Int_filter] descr: [String_filter] name: [String_filter] - parent_ID: [Int_filter] } type AdminService_Genres_input { @@ -485,7 +462,6 @@ input AdminService_Genres_orderBy { ID: SortDirection descr: SortDirection name: SortDirection - parent_ID: SortDirection } type AdminService_Genres_texts { @@ -579,10 +555,8 @@ type CatalogService_Books { See https://cap.cloud.sap/docs/cds/common#type-currency """ currency: CatalogService_Currencies - currency_code: String descr: String genre: CatalogService_Genres - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -597,10 +571,8 @@ input CatalogService_Books_C { chapters: [CatalogService_Chapters_C] createdAt: Timestamp currency: CatalogService_Currencies_C - currency_code: String descr: String genre: CatalogService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -614,10 +586,8 @@ input CatalogService_Books_U { chapters: [CatalogService_Chapters_C] createdAt: Timestamp currency: CatalogService_Currencies_C - currency_code: String descr: String genre: CatalogService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -635,9 +605,7 @@ input CatalogService_Books_filter { ID: [Int_filter] author: [String_filter] createdAt: [Timestamp_filter] - currency_code: [String_filter] descr: [String_filter] - genre_ID: [Int_filter] image: [Binary_filter] modifiedAt: [Timestamp_filter] price: [Decimal_filter] @@ -655,9 +623,7 @@ input CatalogService_Books_orderBy { ID: SortDirection author: SortDirection createdAt: SortDirection - currency_code: SortDirection descr: SortDirection - genre_ID: SortDirection image: SortDirection modifiedAt: SortDirection price: SortDirection @@ -714,7 +680,6 @@ input CatalogService_Books_texts_orderBy { """A Chapter of a Book""" type CatalogService_Chapters { book: CatalogService_Books - book_ID: Int createdAt: Timestamp """Canonical user ID""" @@ -729,7 +694,6 @@ type CatalogService_Chapters { input CatalogService_Chapters_C { book: CatalogService_Books_C - book_ID: Int createdAt: Timestamp createdBy: String modifiedAt: Timestamp @@ -752,7 +716,6 @@ type CatalogService_Chapters_connection { } input CatalogService_Chapters_filter { - book_ID: [Int_filter] createdAt: [Timestamp_filter] createdBy: [String_filter] modifiedAt: [Timestamp_filter] @@ -768,7 +731,6 @@ type CatalogService_Chapters_input { } input CatalogService_Chapters_orderBy { - book_ID: SortDirection createdAt: SortDirection createdBy: SortDirection modifiedAt: SortDirection @@ -888,7 +850,6 @@ type CatalogService_Genres { descr: String name: String parent: CatalogService_Genres - parent_ID: Int texts(filter: [CatalogService_Genres_texts_filter], orderBy: [CatalogService_Genres_texts_orderBy], skip: Int, top: Int): CatalogService_Genres_texts_connection } @@ -898,7 +859,6 @@ input CatalogService_Genres_C { descr: String name: String parent: CatalogService_Genres_C - parent_ID: Int texts: [CatalogService_Genres_texts_C] } @@ -907,7 +867,6 @@ input CatalogService_Genres_U { descr: String name: String parent: CatalogService_Genres_C - parent_ID: Int texts: [CatalogService_Genres_texts_C] } @@ -920,7 +879,6 @@ input CatalogService_Genres_filter { ID: [Int_filter] descr: [String_filter] name: [String_filter] - parent_ID: [Int_filter] } type CatalogService_Genres_input { @@ -933,7 +891,6 @@ input CatalogService_Genres_orderBy { ID: SortDirection descr: SortDirection name: SortDirection - parent_ID: SortDirection } type CatalogService_Genres_texts { @@ -995,9 +952,7 @@ type CatalogService_ListOfBooks { See https://cap.cloud.sap/docs/cds/common#type-currency """ currency: CatalogService_Currencies - currency_code: String genre: CatalogService_Genres - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -1012,9 +967,7 @@ input CatalogService_ListOfBooks_C { chapters: [CatalogService_Chapters_C] createdAt: Timestamp currency: CatalogService_Currencies_C - currency_code: String genre: CatalogService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -1028,9 +981,7 @@ input CatalogService_ListOfBooks_U { chapters: [CatalogService_Chapters_C] createdAt: Timestamp currency: CatalogService_Currencies_C - currency_code: String genre: CatalogService_Genres_C - genre_ID: Int image: Binary modifiedAt: Timestamp price: Decimal @@ -1048,8 +999,6 @@ input CatalogService_ListOfBooks_filter { ID: [Int_filter] author: [String_filter] createdAt: [Timestamp_filter] - currency_code: [String_filter] - genre_ID: [Int_filter] image: [Binary_filter] modifiedAt: [Timestamp_filter] price: [Decimal_filter] @@ -1067,8 +1016,6 @@ input CatalogService_ListOfBooks_orderBy { ID: SortDirection author: SortDirection createdAt: SortDirection - currency_code: SortDirection - genre_ID: SortDirection image: SortDirection modifiedAt: SortDirection price: SortDirection diff --git a/test/schemas/edge-cases/field-named-localized.gql b/test/schemas/edge-cases/field-named-localized.gql index ddd3d4da..6cb32b2d 100644 --- a/test/schemas/edge-cases/field-named-localized.gql +++ b/test/schemas/edge-cases/field-named-localized.gql @@ -45,20 +45,17 @@ type FieldNamedLocalizedService_localized { ID: Int localized: String root: FieldNamedLocalizedService_Root - root_ID: Int } input FieldNamedLocalizedService_localized_C { ID: Int localized: String root: FieldNamedLocalizedService_Root_C - root_ID: Int } input FieldNamedLocalizedService_localized_U { localized: String root: FieldNamedLocalizedService_Root_C - root_ID: Int } type FieldNamedLocalizedService_localized_connection { @@ -69,7 +66,6 @@ type FieldNamedLocalizedService_localized_connection { input FieldNamedLocalizedService_localized_filter { ID: [Int_filter] localized: [String_filter] - root_ID: [Int_filter] } type FieldNamedLocalizedService_localized_input { @@ -81,7 +77,6 @@ type FieldNamedLocalizedService_localized_input { input FieldNamedLocalizedService_localized_orderBy { ID: SortDirection localized: SortDirection - root_ID: SortDirection } input Int_filter { diff --git a/test/schemas/edge-cases/fields-with-connection-names.gql b/test/schemas/edge-cases/fields-with-connection-names.gql index 2b578c2a..1c3de2a6 100644 --- a/test/schemas/edge-cases/fields-with-connection-names.gql +++ b/test/schemas/edge-cases/fields-with-connection-names.gql @@ -46,20 +46,17 @@ input FieldsWithConnectionNamesService_Nodes_orderBy { type FieldsWithConnectionNamesService_Root { ID: ID nodes: FieldsWithConnectionNamesService_Nodes - nodes_ID: ID totalCount: String } input FieldsWithConnectionNamesService_Root_C { ID: ID nodes: FieldsWithConnectionNamesService_Nodes_C - nodes_ID: ID totalCount: String } input FieldsWithConnectionNamesService_Root_U { nodes: FieldsWithConnectionNamesService_Nodes_C - nodes_ID: ID totalCount: String } @@ -70,7 +67,6 @@ type FieldsWithConnectionNamesService_Root_connection { input FieldsWithConnectionNamesService_Root_filter { ID: [ID_filter] - nodes_ID: [ID_filter] totalCount: [String_filter] } @@ -82,7 +78,6 @@ type FieldsWithConnectionNamesService_Root_input { input FieldsWithConnectionNamesService_Root_orderBy { ID: SortDirection - nodes_ID: SortDirection totalCount: SortDirection }