Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphqlSync breaks when upgrading to v16 #3368

Closed
zachsa opened this issue Nov 10, 2021 · 2 comments
Closed

graphqlSync breaks when upgrading to v16 #3368

zachsa opened this issue Nov 10, 2021 · 2 comments

Comments

@zachsa
Copy link

zachsa commented Nov 10, 2021

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)
@n1ru4l
Copy link
Contributor

n1ru4l commented Nov 10, 2021

This is related to #2904

@zachsa
Copy link
Author

zachsa commented Nov 10, 2021

Ah - thank you.

This works:

...

const typeFields = graphqlSync({ schema, source: query }).data

@zachsa zachsa closed this as completed Nov 10, 2021
DanielC-N added a commit to DanielC-N/proskomma-js that referenced this issue Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants