Answer the question
In order to leave comments, you need to log in
GraphQL: Cause of "Query fields must be an object..." error?
Started learning GraphQL.
But either a lot of time has passed since May 24, 2019, or ... I don’t know.
The author's example is reprinted one to one, but he transpiles without problems, and I have a complete plug.
The swearing is: Query fields must be an object with field names as keys or a function which returns such an object. And everything works for the author of the video .
app.js:
const express = require('express');
const { graphqlHTTP } = require('express-graphql'); // кстати, тут в варианте автора тоже не работает, т.к. сейчас импорт из express-graphql надо декомпозировать, сейчас там экспортируется не функция, а объект
const schema = require('../schema/schema');
const app = express();
const PORT = 3005;
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}));
app.listen(PORT, err => {
err ? console.log(err) : console.log('Server started!');
});
const { GraphQLObjectType, GraphQLString, GraphQLSchema } = require('graphql');
const MovieType = new GraphQLObjectType({
name: 'Movie',
fields: () => ({
id: { type: GraphQLString },
name: { type: GraphQLString },
genre: { type: GraphQLString },
}),
});
const Query = new GraphQLObjectType({
name: 'Query',
movie: {
type: MovieType,
args: { id: { type: GraphQLString } },
resolve(parent, args) {
},
},
});
module.exports = new GraphQLSchema({
query: Query,
});
Answer the question
In order to leave comments, you need to log in
Write like this, it should work.
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
movie: {
type: MovieType,
args: {
id: { type: GraphQLString },
},
resolve(parent, args) {},
},
},
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question