gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Schema does not support operation type \"query\"

Open Southclaws opened this issue 3 years ago • 6 comments

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

  • github.com/99designs/gqlgen v0.17.16
  • 1.19 latest

Southclaws avatar Sep 12 '22 22:09 Southclaws

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

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

chaitanyapantheor avatar Nov 08 '22 11:11 chaitanyapantheor

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.

rootkea avatar Nov 22 '22 17:11 rootkea

Ah this makes sense, thanks!

Southclaws avatar Dec 21 '22 10:12 Southclaws

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?

rootkea avatar Dec 21 '22 10:12 rootkea

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

kantum avatar Feb 17 '23 16:02 kantum

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

jakequade-hsm avatar Aug 02 '24 01:08 jakequade-hsm