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

Error: Expected undefined to be a GraphQL schema. on version 16.0.1 #3359

Closed
zorro opened this issue Nov 3, 2021 · 8 comments · Fixed by #3365
Closed

Error: Expected undefined to be a GraphQL schema. on version 16.0.1 #3359

zorro opened this issue Nov 3, 2021 · 8 comments · Fixed by #3365

Comments

@zorro
Copy link

zorro commented Nov 3, 2021

node: 16.13.0
graphql-js: 16.0.1
I tried to run this example from official documentation :

var { graphql, buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
var root = {
	hello: () => {
		return 'Hello world!';
	},
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
	console.log(response);
});

and got this error:

/home/arunz/Downloads/graphql/node_modules/graphql/type/schema.js:35
    throw new Error(
          ^

Error: Expected undefined to be a GraphQL schema.
    at assertSchema (/home/arunz/Downloads/graphql/node_modules/graphql/type/schema.js:35:11)
    at validateSchema (/home/arunz/Downloads/graphql/node_modules/graphql/type/validate.js:34:28)
    at graphqlImpl (/home/arunz/Downloads/graphql/node_modules/graphql/graphql.js:52:64)
    at /home/arunz/Downloads/graphql/node_modules/graphql/graphql.js:21:43
    at new Promise (<anonymous>)
    at graphql (/home/arunz/Downloads/graphql/node_modules/graphql/graphql.js:21:10)
    at Object.<anonymous> (/home/arunz/Downloads/graphql/hello.js:18:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

No error with graphql-js version 15.7.2

@IvanGoncharov
Copy link
Member

@zorro Please use named arguments, since it's expected breaking change.
Please see #2904 for the details.

@IvanGoncharov
Copy link
Member

Keeping it open since it would be a good idea to add temporary devCheck to graphql/execute/subscribe` to make this change less surprising.

@OmgImAlexis
Copy link

@zorro Please use named arguments, since it's expected breaking change. Please see #2904 for the details.

Might want to update the README to prevent users running into this.

@OmgImAlexis
Copy link

Also what are the arguments meant to be? I would have expected schema and query and yet this throws an error.

const {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
  }  = require( 'graphql');
  
  var schema = new GraphQLSchema({
    query: new GraphQLObjectType({
      name: 'RootQueryType',
      fields: {
        hello: {
          type: GraphQLString,
          resolve() {
            return 'world';
          },
        },
      },
    }),
  });

  var query = '{ hello }';

graphql({
    schema,
    query
}).then((result) => {
  // Prints
  // {
  //   data: { hello: "world" }
  // }
  console.log(result);
});

@OmgImAlexis
Copy link

Seems it's expecting source instead of query which really isn't obvious and I honestly feel is going to be confusing for new users.

@Cobertos
Copy link

Cobertos commented Nov 17, 2021

Still receiving this issue on the latest install.

Are there more up to date docs? I was going to make a PR to update the README but it looked like there was a big overhaul/redo of the docs?

Additionally the docs are out of date for graphql() as requestString is now source.

@myarmolik
Copy link

myarmolik commented Dec 6, 2021

When will the documentation be updated :(

@Shaji18
Copy link

Shaji18 commented Dec 13, 2021

For those real beginner like me.
the correct usage of official doc example might have to be like this (not for sure):

graphql({
    schema: schema, 
    source: '{ hello }', 
    rootValue: root
}).then((response) => {
  console.log(response);
});

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

Successfully merging a pull request may close this issue.

6 participants