From 6d2d4c54857ad6d3f45450e2ca2ac35725cfb7b4 Mon Sep 17 00:00:00 2001 From: Mikhail Novikov Date: Thu, 21 Mar 2019 12:14:49 +0200 Subject: [PATCH] chore(gatsby): Update graphql-compose version (#12714) --- .../src/__tests__/extend-node.js | 2 +- .../src/__tests__/on-node-create.js | 2 +- packages/gatsby/package.json | 2 +- .../src/db/__tests__/node-tracking-test.js | 2 +- .../gatsby/src/schema/__tests__/run-query.js | 2 +- .../schema/infer/__tests__/example-value.js | 2 +- .../src/schema/infer/__tests__/infer.js | 2 +- .../src/schema/infer/add-inferred-fields.js | 10 +- packages/gatsby/src/schema/infer/index.js | 6 +- packages/gatsby/src/schema/schema.js | 91 +++++++++++-------- .../schema/types/__tests__/sort-and-filter.js | 4 +- packages/gatsby/src/schema/types/filter.js | 10 +- .../gatsby/src/schema/types/node-interface.js | 2 +- .../gatsby/src/schema/types/pagination.js | 6 +- yarn.lock | 8 +- 15 files changed, 83 insertions(+), 68 deletions(-) diff --git a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js index 7feecab4ebb8e..11fbf583080b3 100644 --- a/packages/gatsby-transformer-remark/src/__tests__/extend-node.js +++ b/packages/gatsby-transformer-remark/src/__tests__/extend-node.js @@ -37,7 +37,7 @@ async function queryResult( const typeName = `MarkdownRemark` const sc = createSchemaComposer() - const tc = sc.createTC(typeName) + const tc = sc.createObjectTC(typeName) addInferredFields({ schemaComposer: sc, typeComposer: tc, diff --git a/packages/gatsby-transformer-remark/src/__tests__/on-node-create.js b/packages/gatsby-transformer-remark/src/__tests__/on-node-create.js index 873597270c283..73b25046f29fb 100644 --- a/packages/gatsby-transformer-remark/src/__tests__/on-node-create.js +++ b/packages/gatsby-transformer-remark/src/__tests__/on-node-create.js @@ -127,7 +127,7 @@ yadda yadda const sc = createSchemaComposer() const typeName = `MarkdownRemark` - const tc = sc.createTC(typeName) + const tc = sc.createObjectTC(typeName) addInferredFields({ schemaComposer: sc, typeComposer: tc, diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index a73144ee1cf1e..efa5d96beb9ba 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -70,7 +70,7 @@ "gatsby-react-router-scroll": "^2.0.6", "glob": "^7.1.1", "graphql": "^14.1.1", - "graphql-compose": "^5.11.0", + "graphql-compose": "^6.0.3", "graphql-playground-middleware-express": "^1.7.10", "graphql-relay": "^0.6.0", "graphql-tools": "^3.0.4", diff --git a/packages/gatsby/src/db/__tests__/node-tracking-test.js b/packages/gatsby/src/db/__tests__/node-tracking-test.js index d646932bfd502..c627eabc499fc 100644 --- a/packages/gatsby/src/db/__tests__/node-tracking-test.js +++ b/packages/gatsby/src/db/__tests__/node-tracking-test.js @@ -96,7 +96,7 @@ describe(`track root nodes`, () => { const sc = createSchemaComposer() const typeName = `Test` - const tc = sc.createTC(typeName) + const tc = sc.createObjectTC(typeName) addInferredFields({ schemaComposer: sc, typeComposer: tc, diff --git a/packages/gatsby/src/schema/__tests__/run-query.js b/packages/gatsby/src/schema/__tests__/run-query.js index 446d77fe6f8c2..13c6219b1cdec 100644 --- a/packages/gatsby/src/schema/__tests__/run-query.js +++ b/packages/gatsby/src/schema/__tests__/run-query.js @@ -141,7 +141,7 @@ function makeGqlType(nodes) { const sc = createSchemaComposer() const typeName = `Test` - const tc = sc.createTC(typeName) + const tc = sc.createObjectTC(typeName) addInferredFields({ schemaComposer: sc, typeComposer: tc, diff --git a/packages/gatsby/src/schema/infer/__tests__/example-value.js b/packages/gatsby/src/schema/infer/__tests__/example-value.js index c75735b7c146e..0fcbd9033e4c6 100644 --- a/packages/gatsby/src/schema/infer/__tests__/example-value.js +++ b/packages/gatsby/src/schema/infer/__tests__/example-value.js @@ -146,7 +146,7 @@ describe(`Get example value for type inference`, () => { const { getFieldsEnum } = require(`../../types/sort`) const sc = createSchemaComposer() - const tc = sc.createTC(`Fields`) + const tc = sc.createObjectTC(`Fields`) addInferredFields({ schemaComposer: sc, typeComposer: tc, diff --git a/packages/gatsby/src/schema/infer/__tests__/infer.js b/packages/gatsby/src/schema/infer/__tests__/infer.js index 254a694ef3127..82d6b53f72d77 100644 --- a/packages/gatsby/src/schema/infer/__tests__/infer.js +++ b/packages/gatsby/src/schema/infer/__tests__/infer.js @@ -247,7 +247,7 @@ describe(`GraphQL type inference`, () => { }, ] const schemaComposer = createSchemaComposer() - const typeComposer = schemaComposer.createTC(`Test`) + const typeComposer = schemaComposer.createObjectTC(`Test`) addInferredFields({ schemaComposer, typeComposer, diff --git a/packages/gatsby/src/schema/infer/add-inferred-fields.js b/packages/gatsby/src/schema/infer/add-inferred-fields.js index 60f65227f4087..1beb8153050d2 100644 --- a/packages/gatsby/src/schema/infer/add-inferred-fields.js +++ b/packages/gatsby/src/schema/infer/add-inferred-fields.js @@ -5,6 +5,7 @@ const { GraphQLObjectType, GraphQLList, } = require(`graphql`) +const { ObjectTypeComposer } = require(`graphql-compose`) const invariant = require(`invariant`) const report = require(`gatsby-cli/lib/reporter`) @@ -136,7 +137,7 @@ const addInferredFieldsImpl = ({ } } } else if (addNewFields) { - if (namedInferredType instanceof schemaComposer.TypeComposer) { + if (namedInferredType instanceof ObjectTypeComposer) { schemaComposer.add(namedInferredType) } typeComposer.setField(key, fieldConfig) @@ -292,7 +293,7 @@ const getFieldConfigFromFieldNameConvention = ({ const typeName = linkedTypes.sort().join(``) + `Union` type = schemaComposer.getOrCreateUTC(typeName, utc => { const types = linkedTypes.map(typeName => - schemaComposer.getOrCreateTC(typeName) + schemaComposer.getOrCreateOTC(typeName) ) utc.setTypes(types) utc.setResolveType(node => node.internal.type) @@ -358,8 +359,9 @@ const getSimpleFieldConfig = ({ originalFieldTypeComposer.getTypeName() ) } else { - fieldTypeComposer = schemaComposer.TypeComposer.createTemp( - createTypeName(selector) + fieldTypeComposer = ObjectTypeComposer.createTemp( + createTypeName(selector), + schemaComposer ) } diff --git a/packages/gatsby/src/schema/infer/index.js b/packages/gatsby/src/schema/infer/index.js index 7bfdfb0b72358..5794d64d100b9 100644 --- a/packages/gatsby/src/schema/infer/index.js +++ b/packages/gatsby/src/schema/infer/index.js @@ -54,7 +54,7 @@ const addInferredTypes = ({ let typeComposer let inferConfig if (schemaComposer.has(typeName)) { - typeComposer = schemaComposer.getTC(typeName) + typeComposer = schemaComposer.getOTC(typeName) inferConfig = getInferConfig(typeComposer) if (inferConfig.infer) { if (!typeComposer.hasInterface(`Node`)) { @@ -62,7 +62,7 @@ const addInferredTypes = ({ } } } else { - typeComposer = schemaComposer.createTC(typeName) + typeComposer = schemaComposer.createObjectTC(typeName) addNodeInterface({ schemaComposer, typeComposer }) } }) @@ -73,7 +73,7 @@ const addInferredTypes = ({ schemaComposer, nodeStore, typeConflictReporter, - typeComposer: schemaComposer.getTC(typeName), + typeComposer: schemaComposer.getOTC(typeName), typeMapping, parentSpan, }) diff --git a/packages/gatsby/src/schema/schema.js b/packages/gatsby/src/schema/schema.js index 95b2c121def81..697eb4041d268 100644 --- a/packages/gatsby/src/schema/schema.js +++ b/packages/gatsby/src/schema/schema.js @@ -6,7 +6,14 @@ const { defaultFieldResolver, assertValidName, getNamedType, + GraphQLObjectType, } = require(`graphql`) +const { + ObjectTypeComposer, + InterfaceTypeComposer, + UnionTypeComposer, + InputTypeComposer, +} = require(`graphql-compose`) const apiRunner = require(`../utils/api-runner-node`) const report = require(`gatsby-cli/lib/reporter`) const { addNodeInterfaceFields } = require(`./types/node-interface`) @@ -50,7 +57,7 @@ const rebuildSchemaWithSitePage = async ({ }) => { const typeComposer = addInferredType({ schemaComposer, - typeComposer: schemaComposer.getTC(`SitePage`), + typeComposer: schemaComposer.getOTC(`SitePage`), nodeStore, typeConflictReporter, typeMapping, @@ -113,7 +120,7 @@ const processTypeComposer = async ({ parentSpan, }) => { if ( - typeComposer instanceof schemaComposer.TypeComposer && + typeComposer instanceof ObjectTypeComposer && typeComposer.hasInterface(`Node`) ) { await addNodeInterfaceFields({ schemaComposer, typeComposer, parentSpan }) @@ -160,8 +167,8 @@ const processAddedType = ({ schemaComposer, type, parentSpan }) => { checkIsAllowedTypeName(typeName) const typeComposer = schemaComposer.get(typeName) if ( - typeComposer instanceof schemaComposer.InterfaceTypeComposer || - typeComposer instanceof schemaComposer.UnionTypeComposer + typeComposer instanceof InterfaceTypeComposer || + typeComposer instanceof UnionTypeComposer ) { if (!typeComposer.getResolveType()) { typeComposer.setResolveType(node => node.internal.type) @@ -195,42 +202,48 @@ const createTypeComposerFromGatsbyType = ({ }) => { switch (type.kind) { case GatsbyGraphQLTypeKind.OBJECT: { - return schemaComposer.TypeComposer.createTemp({ - ...type.config, - interfaces: () => { - if (type.config.interfaces) { - return type.config.interfaces.map(iface => { - if (typeof iface === `string`) { - return schemaComposer.getIFTC(iface).getType() - } else { - return iface - } - }) - } else { - return [] - } + return ObjectTypeComposer.createTemp( + { + ...type.config, + interfaces: () => { + if (type.config.interfaces) { + return type.config.interfaces.map(iface => { + if (typeof iface === `string`) { + return schemaComposer.getIFTC(iface).getType() + } else { + return iface + } + }) + } else { + return [] + } + }, }, - }) + schemaComposer + ) } case GatsbyGraphQLTypeKind.INPUT_OBJECT: { - return schemaComposer.InputTypeComposer.createTemp(type.config) + return InputTypeComposer.createTemp(type.config, schemaComposer) } case GatsbyGraphQLTypeKind.UNION: { - return schemaComposer.UnionTypeComposer.createTemp({ - ...type.config, - types: () => { - if (type.types) { - return type.types.map(typeName => - schemaComposer.getTC(typeName).getType() - ) - } else { - return [] - } + return UnionTypeComposer.createTemp( + { + ...type.config, + types: () => { + if (type.types) { + return type.types.map(typeName => + schemaComposer.getOTC(typeName).getType() + ) + } else { + return [] + } + }, }, - }) + schemaComposer + ) } case GatsbyGraphQLTypeKind.INTERFACE: { - return schemaComposer.InterfaceTypeComposer.createTemp(type.config) + return InterfaceTypeComposer.createTemp(type.config, schemaComposer) } default: { console.warn(`Illegal type definition: ${JSON.stringify(type.config)}`) @@ -246,10 +259,7 @@ const addSetFieldsOnGraphQLNodeTypeFields = ({ }) => Promise.all( Array.from(schemaComposer.values()).map(async tc => { - if ( - tc instanceof schemaComposer.TypeComposer && - tc.hasInterface(`Node`) - ) { + if (tc instanceof ObjectTypeComposer && tc.hasInterface(`Node`)) { const typeName = tc.getTypeName() const result = await apiRunner(`setFieldsOnGraphQLNodeType`, { type: { @@ -277,7 +287,7 @@ const addThirdPartySchemas = ({ }) => { thirdPartySchemas.forEach(schema => { const schemaQueryType = schema.getQueryType() - const queryTC = schemaComposer.TypeComposer.createTemp(schemaQueryType) + const queryTC = ObjectTypeComposer.createTemp(schemaQueryType) const fields = queryTC.getFields() schemaComposer.Query.addFields(fields) @@ -289,10 +299,11 @@ const addThirdPartySchemas = ({ if ( type !== schemaQueryType && !isSpecifiedScalarType(type) && - !isIntrospectionType(type) + !isIntrospectionType(type) && + type instanceof GraphQLObjectType ) { type.isThirdPartyType = true - const typeComposer = schemaComposer.TypeComposer.createTemp(type) + const typeComposer = ObjectTypeComposer.createTemp(type) typeComposer.getFieldNames().forEach(fieldName => { const fieldType = typeComposer.getFieldType(fieldName) if (getNamedType(fieldType) === schemaQueryType) { @@ -313,7 +324,7 @@ const addCustomResolveFunctions = async ({ schemaComposer, parentSpan }) => { Object.keys(resolvers).forEach(typeName => { const fields = resolvers[typeName] if (schemaComposer.has(typeName)) { - const tc = schemaComposer.getTC(typeName) + const tc = schemaComposer.getOTC(typeName) Object.keys(fields).forEach(fieldName => { const fieldConfig = fields[fieldName] if (tc.hasField(fieldName)) { diff --git a/packages/gatsby/src/schema/types/__tests__/sort-and-filter.js b/packages/gatsby/src/schema/types/__tests__/sort-and-filter.js index 46a2b68e03608..22204388cc674 100644 --- a/packages/gatsby/src/schema/types/__tests__/sort-and-filter.js +++ b/packages/gatsby/src/schema/types/__tests__/sort-and-filter.js @@ -23,7 +23,7 @@ const { GraphQLJSON } = require(`graphql-compose`) const getInferredFields = fields => { const schemaComposer = createSchemaComposer() - const tc = schemaComposer.createTC({ name: `Test`, fields }) + const tc = schemaComposer.createObjectTC({ name: `Test`, fields }) return getFilterInput({ schemaComposer, typeComposer: tc }) .getType() .getFields() @@ -432,7 +432,7 @@ describe(`GraphQL Input args from fields`, () => { } const schemaComposer = createSchemaComposer() - const tc = schemaComposer.createTC({ name: `Test`, fields }) + const tc = schemaComposer.createObjectTC({ name: `Test`, fields }) const sort = getSortInput({ schemaComposer, typeComposer: tc, diff --git a/packages/gatsby/src/schema/types/filter.js b/packages/gatsby/src/schema/types/filter.js index 3d829e71cebfd..35d894fe24042 100644 --- a/packages/gatsby/src/schema/types/filter.js +++ b/packages/gatsby/src/schema/types/filter.js @@ -6,6 +6,7 @@ const { GraphQLList, isSpecifiedScalarType, } = require(`graphql`) +const { InputTypeComposer } = require(`graphql-compose`) const { GraphQLJSON } = require(`graphql-compose`) const { GraphQLDate } = require(`./date`) @@ -24,11 +25,12 @@ const convert = ({ } else if (schemaComposer.has(inputTypeName)) { return schemaComposer.getITC(inputTypeName) } else { - convertedITC = new schemaComposer.InputTypeComposer( + convertedITC = new InputTypeComposer( new GraphQLInputObjectType({ name: inputTypeName, fields: {}, - }) + }), + schemaComposer ) } @@ -41,7 +43,7 @@ const convert = ({ const type = getNamedType(fieldConfig.type) if (type instanceof GraphQLInputObjectType) { - const itc = new schemaComposer.InputTypeComposer(type) + const itc = new InputTypeComposer(type, schemaComposer) const operatorsInputTC = convert({ schemaComposer, @@ -85,7 +87,7 @@ const removeEmptyFields = ( const nonEmptyFields = {} Object.keys(fields).forEach(fieldName => { const fieldITC = fields[fieldName] - if (fieldITC instanceof schemaComposer.InputTypeComposer) { + if (fieldITC instanceof InputTypeComposer) { const convertedITC = convert(fieldITC) if (convertedITC.getFieldNames().length) { nonEmptyFields[fieldName] = convertedITC diff --git a/packages/gatsby/src/schema/types/node-interface.js b/packages/gatsby/src/schema/types/node-interface.js index a2552aba30643..ef4dd46ac95a2 100644 --- a/packages/gatsby/src/schema/types/node-interface.js +++ b/packages/gatsby/src/schema/types/node-interface.js @@ -2,7 +2,7 @@ const getOrCreateNodeInterface = schemaComposer => { // TODO: why is `mediaType` on Internal? Applies only to File!? // `fieldOwners` is an object // Should we drop ignoreType? - const internalTC = schemaComposer.getOrCreateTC(`Internal`, tc => { + const internalTC = schemaComposer.getOrCreateOTC(`Internal`, tc => { tc.addFields({ content: `String`, contentDigest: `String!`, diff --git a/packages/gatsby/src/schema/types/pagination.js b/packages/gatsby/src/schema/types/pagination.js index a9dd0006c1f49..f217131c5e480 100644 --- a/packages/gatsby/src/schema/types/pagination.js +++ b/packages/gatsby/src/schema/types/pagination.js @@ -2,7 +2,7 @@ const { getFieldsEnum } = require(`./sort`) const { distinct, group } = require(`../resolvers`) const getPageInfo = ({ schemaComposer }) => - schemaComposer.getOrCreateTC(`PageInfo`, tc => { + schemaComposer.getOrCreateOTC(`PageInfo`, tc => { tc.addFields({ hasNextPage: `Boolean!`, // currentPage: `Int!`, @@ -15,7 +15,7 @@ const getPageInfo = ({ schemaComposer }) => const getEdge = ({ schemaComposer, typeComposer }) => { const typeName = typeComposer.getTypeName() + `Edge` - return schemaComposer.getOrCreateTC(typeName, tc => { + return schemaComposer.getOrCreateOTC(typeName, tc => { tc.addFields({ next: typeComposer, node: typeComposer.getTypeNonNull(), @@ -30,7 +30,7 @@ const createPagination = ({ fields, typeName, }) => { - const paginationTypeComposer = schemaComposer.getOrCreateTC(typeName, tc => { + const paginationTypeComposer = schemaComposer.getOrCreateOTC(typeName, tc => { tc.addFields({ totalCount: `Int!`, edges: [getEdge({ schemaComposer, typeComposer }).getTypeNonNull()], diff --git a/yarn.lock b/yarn.lock index 764973e84736a..4fdad50fc89f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8562,10 +8562,10 @@ graceful-fs@^4.1.15, graceful-fs@^4.1.9: version "1.0.1" resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" -graphql-compose@^5.11.0: - version "5.11.0" - resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-5.11.0.tgz#371a75036897777be7e16e861f8afa86567b0ca1" - integrity sha512-TLdHXgjvylxIjijKEI+R8ofI4OB1l8t5npVeIg2rRzuuGu6zkZ93hbUu4kd0McoaoTxnMDmiRYmkKHNpZI7PYg== +graphql-compose@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-6.0.3.tgz#fa5668a30694abef4166703aa03af07a741039a8" + integrity sha512-QpywEtNvlEQS0a5VIseMA/tk67QmEN9NNUx1B1tzGR/p7MePyus9wvci2cIP/mwdDrvLRRbwpmidSKQXFD3SEA== dependencies: graphql-type-json "^0.2.1" object-path "^0.11.4"