shurcooL / graphql

Package graphql provides a GraphQL client implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Structs used in variables need json tags: not intuitive and not documented.

dmitshur opened this issue · comments

See issue 19.

Structs used in variables need to have json tags to match the names that the GraphQL server expects. E.g.:

type ProductInput struct {
	Name     graphql.String `json:"name"`
	Location graphql.String `json:"location"`
}

This is not intuitive, and currently not documented.

I should either:

  • Document this so it's clear this must be done.

  • Improve the graphql code to make it no longer neccessary to manually specify those json tags.

    They can be inferred from the field name, just need to convert from Go's MixedCaps case to GraphQL's lowerCamelCase (this is already being done for queries, the code for it exists in ident package).

Please add this to the documentation. I probably spent a day or two on this problem :)