Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic occurred: interface conversion: resolvable.Resolvable is nil, not *resolvable.Object #125

Closed
thewillhuang opened this issue Nov 18, 2017 · 6 comments

Comments

@thewillhuang
Copy link

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
}
@vergenzt
Copy link

vergenzt commented Nov 18, 2017

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.

@thewillhuang
Copy link
Author

oh doh....... thank you!

@thewillhuang
Copy link
Author

just tried it and it worked, thanks again really appreciate it 👍

@vergenzt
Copy link

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.

vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`)

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`)

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`)

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`) It
now panics with `graphql: must provide "schema" definition with "query"
type or a type named "Query"`

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`) It
now errors at schema parse time with `graphql: must provide "schema"
definition with "query" type or a type named "Query"`.

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
vergenzt added a commit to vergenzt/graphql-go that referenced this issue Nov 19, 2017
Consistent with [schema parsing behavior from graphql-js][1], this
commit allows graphql-go to infer entry point types without an explicit
`schema` declaration if there are types in the schema named "Query",
"Mutation", or "Subscription".

It also returns a more descriptive error message if no query type is
declared, which fixes graph-gophers#125. Previously if no `schema` declaration was
present a cryptic panic would be thrown at runtime. (`interface
conversion: resolvable.Resolvable is nil, not *resolvable.Object`) It
now errors at schema parse time with `graphql: must provide "schema"
definition with "query" type or a type named "Query"`.

[1]: https://github.com/graphql/graphql-js/blob/master@{2017-11-18}/src/utilities/buildASTSchema.js#L167-L221
@smithaitufe
Copy link

smithaitufe commented Apr 25, 2018

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

@pavelnikolov
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants