panic occurred: interface conversion: resolvable.Resolvable is nil, not *resolvable.Object
thewillhuang opened this issue ยท 6 comments
hey guys, how do I get past this error and what am I doing wrong?
panic occurred: interface conversion: resolvable.Resolvable is nil, not *resolvable.Object
below I have my schema and resolvers for reference, thanks in advance for your help
scalar Time
interface Node {
id: ID!
}
type User implements Node {
id: ID!
updated: Time!
created: Time!
name: String!
email: String!
}
type Mutation {
signup(name: String!, email: String!, password: String!): User
}
schema {
mutation: Mutation
}
type Resolver struct{}
type Node struct {
result interface{}
}
type Entity interface {
Id() graphql.ID
Created() graphql.Time
Updated() graphql.Time
}
type userInterface interface {
Entity
Name() string
Email() string
}
type user struct {
ID graphql.ID
Name string
Email string
Created graphql.Time
Updated graphql.Time
}
type userResolver struct {
u *user
}
// Signup mutation
func (r *Resolver) Signup(ctx context.Context, args struct {
Email string
Name string
Password string
}) (*userResolver, error) {
u := &user{
Name: args.Name,
Email: args.Email,
ID: "1",
Created: graphql.Time{Time: time.Now()},
Updated: graphql.Time{Time: time.Now()},
}
return &userResolver{
u,
}, nil
}
// // user resolvers
func (u *userResolver) ID(ctx context.Context) (graphql.ID, error) {
return u.u.ID, nil
}
func (u *userResolver) Created(ctx context.Context) (graphql.Time, error) {
return u.u.Created, nil
}
func (u *userResolver) Updated(ctx context.Context) (graphql.Time, error) {
return u.u.Updated, nil
}
func (u *userResolver) Name(ctx context.Context) (string, error) {
return u.u.Name, nil
}
func (u *userResolver) Email(ctx context.Context) (string, error) {
return u.u.Email, nil
}
I've seen that error before. When I encountered it it ended up being because I had forgotten to declare schema { query: Query }
. (I had just declared my query type and went on my merry way.)
I think the problem in your case is that schemas must have a Query type. It's not optional. (See Initial Types from the spec: "The query type must always be provided, and is an Object base type.")
Try adding an empty query object to the schema:
type Query { }
schema {
query: Query
mutation: Mutation
}
This case should definitely panic with a better error message though, so IMO this issue should stay open.
oh doh....... thank you!
just tried it and it worked, thanks again really appreciate it ๐
Np! I'm working on a PR btw to give a better error message in this case since it's an easy mistake to make.
Please what should be the datatype
that will hold the value of graphql.Time
in postgres?
I am having this error
converting argument $3 type: unsupported type graphql.Time, a struct
This issue has been fixed by #364
Now you would get an error:
root operation "Query" must be defined
This is the code that returns the error.