Gqlgen: panic: interface conversion: types.Type is *types.Basic, not *types.Named

Created on 27 Apr 2019  路  12Comments  路  Source: 99designs/gqlgen

Got a panic when i tried to go run github.com/99designs/gqlgen

I expected the codes to be generated without any issue/error

schema.graphql seems fine

versions

  • gqlgen version? v0.8.3
  • go version? - go version go1.12.1 linux/amd64
  • dep or go modules? - Go modules

panic output


panic: interface conversion: types.Type is *types.Basic, not *types.Named

goroutine 1 [running]:
github.com/99designs/gqlgen/codegen.(*builder).bindField(0xc0010e18e8, 0xc000915880, 0xc00013d320, 0x0, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/codegen/field.go:111 +0x103d
github.com/99designs/gqlgen/codegen.(*builder).buildField(0xc0010e18e8, 0xc000915880, 0xc00026e4d0, 0x0, 0xe9ca00, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/codegen/field.go:64 +0x31d
github.com/99designs/gqlgen/codegen.(*builder).buildObject(0xc0010e18e8, 0xc0000b4e40, 0x9db536, 0x6, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/codegen/object.go:73 +0x4ec
github.com/99designs/gqlgen/codegen.BuildData(0xc0002120c0, 0xab5c40, 0xe9ba48, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/codegen/data.go:84 +0x461
github.com/99designs/gqlgen/api.Generate(0xc0002120c0, 0x0, 0x0, 0x0, 0x0, 0xa1c290)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/api/generate.go:37 +0x253
github.com/99designs/gqlgen/cmd.glob..func1(0xc00021a000)
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/cmd/gen.go:39 +0xa2
github.com/urfave/cli.HandleAction(0x91f560, 0xa1b560, 0xc00021a000, 0xc0000724e0, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/urfave/[email protected]/app.go:492 +0x7c
github.com/urfave/cli.(*App).Run(0xc000210000, 0xc000094190, 0x1, 0x1, 0x0, 0x0)
        /home/adigun/GoApps/pkg/mod/github.com/urfave/[email protected]/app.go:264 +0x590
github.com/99designs/gqlgen/cmd.Execute()
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/cmd/root.go:40 +0x224
main.main()
        /home/adigun/GoApps/pkg/mod/github.com/99designs/[email protected]/main.go:8 +0x20
exit status 2

gqlgen.yml


schema:
- schema.graphql
exec:
  filename: server/generated.go
model:
  filename: server/models_gen.go
resolver:
  filename: server/resolver.go
  type: Resolver
bug v0.9

All 12 comments

I am experiencing this problem too

This is a bad error message for sure, but it's not clear what the cause is. Can you please provide the schema you used for this?

Am currently facing this issues and am new to GoLang so it;s a bit more difficult to debug

My schema ;

schema {
    query: Query
    mutation: Mutation 
}

type Query {
    outlet(id: ID!): [Outlet]
    user(id: ID!): [User]
    technician(id: ID!): [Technician]
}

type Mutation {
    createOutlet(input: NewOutlet!): Outlet!
    createUser(input: NewUser!): User!
}


type Outlet {
    id: ID!
    name: String!
    images: String!
    location: String!
    description: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
    owner: User!
    technician: Technician!
}

type Technician {
    id: ID!
    name: String!
    image: String!
    location: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
    price: String!
    outlet: Outlet!
}

type User {
    id: ID!
    name: String!
    image: String!
    email: String!
    outlet: Outlet!
}


input NewOutlet {
    id: ID!
    name: String!
    images: String!
    location: String!
    description: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
}

input NewUser {
    name: String
}


@darmie @adigunhammedolalekan any help on how you fixed your's ?

Or what you did wrong to generate that error ?

@vickywane the problem is due to one of the relationships.

I debugged it by adding each field line by line till I found the culprit. Making the field an array fixed the problem.

I suspect that the problem in your case is coming from the relationships between Outlet and User or Technician. @vickywane . The generator is probably having a hard time creating the relationships in Golang. Try and be creative the fields and see which one fixes the problem

Alright . When i tried a simpler model it worked . I'll make adjustments and try again .

I remodeled my schema to look like this ;

schema {
    query: Query
    mutation: Mutation 
}

type Query {
    outlet(id: ID): [Outlet]
    maintainer(id: ID): [Maintainer]
    technician(id: ID): [Technician]
}

type Mutation {
    createOutlet(input: NewOutlet!): Outlet!
    createMaintainer(input: newMaintainer!): Maintainer!
}


type Outlet {
    id: ID!
    name: String!
    images: String!
    location: String!
    description: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
}

type Technician {
    id: ID!
    name: String!
    image: String!
    location: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
    price: String!
    outlet: Outlet!
}

type Maintainer {
    id: ID!
    name: String!
    image: String!
    email: String!
    outlet: Outlet!
}


input NewOutlet {
    id: ID!
    name: String!
    images: String!
    location: String!
    description: String!
    state: String!
    country: String!
    email: String!
    helpline: String!
}

input newMaintainer {
    id: Int
    name: String
    image: String
    email: String
}

However whenever i add
owner: Maintainer! technician: Technician!
as relationships to Outlet i get the original error and am left wondering why so ... Since other relationships work

@vickywane have you tried my suggestion? set the relationship field types as an array

owner: [Maintainer!]
technician: [Technician!]

see if it works

@darmie That fixed it .. thanks . However, i didn't want those field to contain arrays.

Yes, the sacrifices we have to make lol. Just make sure the array contains a single item.

Had the same error message; for me it was because I had a func with the same name as a GQL type in my schema (func New...() in my model and input New... in my GQL schema).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sumanthakannantha picture sumanthakannantha  路  3Comments

steebchen picture steebchen  路  3Comments

jacksontj picture jacksontj  路  4Comments

itsbalamurali picture itsbalamurali  路  4Comments

cemremengu picture cemremengu  路  3Comments