graph-gophers / graphql-go

GraphQL server with a focus on ease of use
BSD 2-Clause "Simplified" License
4.65k stars 492 forks source link

Add graphql reflect tag #596

Closed pavelnikolov closed 1 year ago

pavelnikolov commented 1 year ago

This PR allows fields to have a graphql reflect tag in order to override the name of the field they resolve. This in turn would allow for field resolvers which are case-sensitive. Currently the library matches fields using case-insensitive matching and the _ char is insignificant. This violates the official GraphQL spec which states that names should be case-sensitive and the _ is significant.

With this change, similar to the json reflect tag, users can set a graphql tag in order to override the name. For example:

type resolver struct {
    Hello string `graphql:"hello"`
}

or

type resolver struct {
    Greeting string `graphql:"hello"`
}

The above would allow the users to override the name and use a case-sensitive matching. Both of the above resolvers would resolve a schema like this:

type Query {
    hello: String!
}

fixes: #593