Skip to content

graphqlSync breaks when upgrading to v16 #3368

@zachsa

Description

@zachsa

I am using graphqlSync to execute code against a schema on app startup. Upgrading from graphql@15 to graphql@16 (and no other changes) breaks my code.

import { makeExecutableSchema } from '@graphql-tools/schema'
import { graphqlSync, print } from 'graphql'
import { gql } from 'apollo-server-koa'

const schema = makeExecutableSchema({
  typeDefs: '...',
  resolvers: {...},
})

const query = print(
  gql`
      query {
        p: __type(name: "InputOne") {
          inputFields {
            name
            type {
              kind
            }
          }
        }
        m: __type(name: "InputTwo") {
          inputFields {
            name
            type {
              kind
            }
          }
        }
        a: __type(name: "InputThree") {
          inputFields {
            name
            type {
              kind
            }
          }
        }
      }
    `
)

console.log(schema) // Prints out a schema
console.log(query) // Prints out a query

const typeFields = graphqlSync( schema, query ).data

The above fails using graphql@16 with the following error:

/home/.../src/api/node_modules/graphql/type/schema.js:35
    throw new Error(
          ^

Error: Expected undefined to be a GraphQL schema.
    at assertSchema (/home/.../src/api/node_modules/graphql/type/schema.js:35:11)
    at validateSchema (/home/.../src/api/node_modules/graphql/type/validate.js:34:28)
    at graphqlImpl (/home/.../src/api/node_modules/graphql/graphql.js:52:64)
    at graphqlSync (/home/.../src/api/node_modules/graphql/graphql.js:31:18)
    at file:///home/.../src/graphql/schema/index.js:30:20
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions