For some reason, when using the schema below, I get the error "GraphQL middleware options must contain a schema." when trying to load the GraphiQL page, and an error status 500 when making requests from my react app. Here is my code:
server.js
const express = require('express');const { graphqlHTTP } = require('express-graphql');const clientSchema = require('./schemas/clientSchema');]const app = express();const cors = require('cors');app.use(cors());app.use('/graphql', graphqlHTTP({ clientSchema, graphiql: true}));module.exports = app;
clientSchema.js
const graphql = require('graphql');const account = require('../queries/account');const { GraphQLObjectType, GraphQLString, GraphQLSchema, GraphQLID, GraphQLInt, GraphQLFloat, GraphQLList, GraphQLNonNull, GraphQLBoolean} = graphql;const AccountType = new GraphQLObjectType({ name: 'Account', fields: () => ({ id: { type: GraphQLID }, name: { type: GraphQLString }, email: { type: GraphQLString }, phone: { type: GraphQLString }, password: { type: GraphQLString } })})const Mutation = new GraphQLObjectType({ name: 'Mutation', fields: { createAccount: { type: AccountType, args: { name: { type: new GraphQLNonNull(GraphQLString) }, email: { type: new GraphQLNonNull(GraphQLString) }, password: { type: new GraphQLNonNull(GraphQLString)} }, async resolve(parent, args) { return await account.createAccount({ name: args.name, email: args.email, password: args.password }); } } }})module.exports = new GraphQLSchema({ mutation: Mutation})
Any help would be greatly appreciated. Thank you.