1

I'm trying to run express server with graphql and I get the following error:

Error: Query.example field type must be Output Type but got: [object Object].

express-graphql used in a route:

app.use('/graphql', graphqlHTTP(req => ({
 schema,
 pretty: true
})));

The schema looks like that:

export default new GraphQLSchema({
 query: new GraphQLObjectType({
    name: 'Query',
    fields: queries
 })
});

Queries has only one query that imported from here:

import {
 GraphQLList,
 GraphQLID,
 GraphQLNonNull
} from 'graphql';

import exampleScheme from '../models/schemes/example';
import {example as exampleData}  from '../models/jsons'

export default {
 type: exampleScheme,
 resolve (root, params, options) {
     return exampleData;
 }
};

The schemas (exampleScheme) and data (exampleScheme) are working on another project so I assume they're not the problem.

Any ideas? What does 'Output type' mean?

0

1 Answer 1

2

if

export default {
 type: exampleScheme,
 resolve (root, params, options) {
     return exampleData;
 }
};

is your queries, then you got it wrong, Query's fields, hence queries in your example, should be looking like this:

export default {
 helloString: {
     type: GraphQLString,
     resolve (root, params, options) {
         return "Hello World!";
     }
 }
 ... <Next query>
};

anyway, the error is that 'type' is not a valid GraphQLType. then the query will look like this

query {
   testString
}

will result in:

{
    testString: "Hello World!"
}

if the meaning was that the exampleScheme is some other object, please make sure you are creating it using:

new GraphQLObjectType({ .... Options });

Hope it helps! :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks HagaiCo, because I imported the schemes from another project, exmaple scheme was a 'GraphQLSchema' instead of 'GraphQLObjectType'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.