Skip to content

Commit

Permalink
chore(gatsby): Update graphql-compose version (gatsbyjs#12714)
Browse files Browse the repository at this point in the history
  • Loading branch information
freiksenet authored and sidharthachatterjee committed Mar 21, 2019
1 parent a8e1a0a commit 6d2d4c5
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/db/__tests__/node-tracking-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/__tests__/run-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/infer/__tests__/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe(`GraphQL type inference`, () => {
},
]
const schemaComposer = createSchemaComposer()
const typeComposer = schemaComposer.createTC(`Test`)
const typeComposer = schemaComposer.createObjectTC(`Test`)
addInferredFields({
schemaComposer,
typeComposer,
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby/src/schema/infer/add-inferred-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -358,8 +359,9 @@ const getSimpleFieldConfig = ({
originalFieldTypeComposer.getTypeName()
)
} else {
fieldTypeComposer = schemaComposer.TypeComposer.createTemp(
createTypeName(selector)
fieldTypeComposer = ObjectTypeComposer.createTemp(
createTypeName(selector),
schemaComposer
)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/schema/infer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ 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`)) {
noNodeInterfaceTypes.push(typeComposer.getType())
}
}
} else {
typeComposer = schemaComposer.createTC(typeName)
typeComposer = schemaComposer.createObjectTC(typeName)
addNodeInterface({ schemaComposer, typeComposer })
}
})
Expand All @@ -73,7 +73,7 @@ const addInferredTypes = ({
schemaComposer,
nodeStore,
typeConflictReporter,
typeComposer: schemaComposer.getTC(typeName),
typeComposer: schemaComposer.getOTC(typeName),
typeMapping,
parentSpan,
})
Expand Down
91 changes: 51 additions & 40 deletions packages/gatsby/src/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -50,7 +57,7 @@ const rebuildSchemaWithSitePage = async ({
}) => {
const typeComposer = addInferredType({
schemaComposer,
typeComposer: schemaComposer.getTC(`SitePage`),
typeComposer: schemaComposer.getOTC(`SitePage`),
nodeStore,
typeConflictReporter,
typeMapping,
Expand Down Expand Up @@ -113,7 +120,7 @@ const processTypeComposer = async ({
parentSpan,
}) => {
if (
typeComposer instanceof schemaComposer.TypeComposer &&
typeComposer instanceof ObjectTypeComposer &&
typeComposer.hasInterface(`Node`)
) {
await addNodeInterfaceFields({ schemaComposer, typeComposer, parentSpan })
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)}`)
Expand All @@ -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: {
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/schema/types/__tests__/sort-and-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby/src/schema/types/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
GraphQLList,
isSpecifiedScalarType,
} = require(`graphql`)
const { InputTypeComposer } = require(`graphql-compose`)
const { GraphQLJSON } = require(`graphql-compose`)
const { GraphQLDate } = require(`./date`)

Expand All @@ -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
)
}

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/types/node-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!`,
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/schema/types/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!`,
Expand All @@ -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(),
Expand All @@ -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()],
Expand Down
Loading

0 comments on commit 6d2d4c5

Please sign in to comment.