graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.82k stars 836 forks source link

How to disable introspection? And feature request for manually adding authentication headers. #649

Open Aravind1411 opened 1 year ago

Aravind1411 commented 1 year ago

I've seen a closed issue regarding disabling introspection in grahql playground. As the solution was deleted, still not clear how to disable introspection in golang. Basically I just wanna see the schema and not run the query. How can I achieve this?

jesko-plitt commented 1 year ago

You can disable schema introspection:

graphql.SchemaMetaFieldDef.Resolve = func(p graphql.ResolveParams) (interface{}, error) {
    return graphql.Schema{}, nil
}

And you can re-enable it, too:

graphql.SchemaMetaFieldDef.Resolve = func(p ResolveParams) (interface{}, error) {
    return p.Info.Schema, nil
}

Feels a bit hacky though...