Error: "user" defined in resolvers, but not in schema
See original GitHub issueSorry to just dump my code on you guys, but I don’t really know what to do here. Following advice found here:
https://github.com/apollographql/apollo-server/issues/1998
schema.js
import { makeExecutableSchema } from 'apollo-server-express'
import ApplicationSchema from './types'
import Resolvers from './resolvers'
export default makeExecutableSchema({
typeDefs: ApplicationSchema,
resolvers: Resolvers
})`
resolvers/index.js
`import user from './user'
export default {
user
}
resolvers/user.js
import Joi from 'joi'
import mongoose from 'mongoose'
import { UserInputError } from 'apollo-server-express'
import { signUp, signIn } from '../validators'
import { User } from '../schemata' // mongoose schema
import * as Authentication from '../authentication'
export default {
Query: {
me: (root, args, { request }, info) => {
Authentication.checkSignedIn(request)
return User.findbyId(request.session.userId)
},
users: (root, args, { request }, info) => {
Authentication.checkSignedIn(request)
User.find({})
},
user: (root, args, { request }, info) => {
const { id } = args
Authentication.checkSignedIn(request)
if (!mongoose.Types.ObjectId.isValid(id)) {
throw new UserInputError(`${id} is not a valid user ID.`)
}
return User.findById(id)
}
},
Mutation: {
signup: async (root, args, { request }, info) => {
Authentication.checkSignedOut(request)
await Joi.validate(args, signUp, { abortEarly: false })
return User.create(args)
},
signIn: async (root, args, { request }, info) => {
const { userId } = request.session
if (userId) return User.findById(userId)
await Joi.validate(args, signIn, { abortEarly: false })
const user = await Authentication.attemptSignIn(args)
request.session.userId = user.id
return user
},
signOut: async (root, args, { request, response }, info) => {
Authentication.checkSignedIn(request)
return Authentication.signOut(request, response)
}
}
}
types/index.js
import root from './root'
import user from './user'
export default [
root,
user
]
types/root,js
import { gql } from 'apollo-server-express'
export default gql`
type Query {
_: String
}
type Mutation {
_: String
}
type Subscription {
_: String
}
types/user.js
import { gql } from 'apollo-server-express'
export default gql`
type User {
id: ID!
email: String!
username: String!
name: String!
password: String!
createdAt: String!
}
extend type Query {
me: User
user(id: ID!): User
users: [User!]!
}
extend type Mutation {
signUp(email: String!, username: String!, name: String!): User
signIn(email: String!, password: String!): User
signOut: Boolean
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
GraphQL : the object name is defined in resolvers, but not in ...
So I defined the new Object in the schema and in the resolver using GraphQLObjectType. However I m getting this error : Error:...
Read more >'Defined in resolvers, but not in schema' need help! - apollo
Hi everybody,. I'm starting with Apollo and hit the following error when defining a new mutation: “Error: “sendResetPasswordEmail” defined ...
Read more >How to resolve 'X defined in resolvers, but not in schema' with ...
The root cause here is that the babel-plugin-inline-import plugin caches your schema. The resolution is essentially to have BABEL_DISABLE_CACHE=1 in your .env , ......
Read more >Creating a GraphQL Server with Apollo
Define a schema and resolvers, a Schema is needed to describe our types. Resolvers are functions that are invoked to handle queries from...
Read more >Resolvers - Apollo GraphQL Docs
Notice that this example doesn't define resolvers for User fields ( id and name ). That's because the default resolver that Apollo Server...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also had this error, except it was for a propery of one of my types:
Error: Workspace.link defined in resolvers, but not in schema
I made a different, way dumber mistake- a good ol’ fashion copy-paste error:
So, Workspace was being treated like it was a Link object. Drove me very close to insanity!
The reason for this error is because user was defined in server.js, but not in schema.graphql. It needs to be defined in both.