99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.96k stars 1.17k forks source link

Schema does not support operation type \"query\" #2365

Open Southclaws opened 2 years ago

Southclaws commented 2 years ago

What happened?

Trying to use the embedded playground and I'm just getting 422 unprocessable entity:

{"errors":[{"message":"Schema does not support operation type \"query\"","locations":[{"line":2,"column":5}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}}],"data":null}

What did you expect?

Operation query to work.

Minimal graphql.schema and models to reproduce

https://github.com/Southclaws/storyden

Fire this up to reproduce, visit http://localhost:8000/graphql/ui for the graphiql interface that's failing.

The setup code for the graphql server is in app/transports/graphql/graphql.go

versions

chaitanyapantheor commented 2 years ago

@Southclaws i guess its not able to resolve on path /query

do something like this in your server file mux.Handle("/query", s) here

rootkea commented 1 year ago

No, this is due to Query being not there in schema. Try adding dummy type Query in https://github.com/Southclaws/storyden/blob/main/api/thread.graphqls and you'll see the error getting vanished.

This seems to be a bug in schema validator as there can be schemas without Query type. FWIW, this error message originates from gqlparser package.

Southclaws commented 1 year ago

Ah this makes sense, thanks!

rootkea commented 1 year ago

Please let's not close this before this get fixed or an appropriate issue is reported at relevant package. Why should there be a compulsion to have Query in the schema?

kantum commented 1 year ago

I'm making an atomic API with only some mutation, I would like to be able to have no query at all.

jakequade-hsm commented 3 months ago

Late to the party - but this can also be due to your glqgen.yml file. I had to change/add these two parts:


federation:
  filename: ./internal/gql/generated/federation.go
  package: generated

model:
  filename: ./internal/gql/gqlmodel/models_gen.go
  package: gqlmodel