Graphql-go: panic occurred: interface conversion: resolvable.Resolvable is nil, not *resolvable.Object

Created on 19 Nov 2017  路  5Comments  路  Source: graph-gophers/graphql-go

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
}

Most helpful comment

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.

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rogchap picture rogchap  路  5Comments

vladimiroff picture vladimiroff  路  6Comments

dengliu picture dengliu  路  5Comments

saward picture saward  路  6Comments

Hagbarth picture Hagbarth  路  6Comments