hasura / go-graphql-client

Package graphql provides a GraphQL client implementation.
MIT License
395 stars 91 forks source link

Invalid serialisation containing commas with embedded struct #122

Closed andig closed 7 months ago

andig commented 7 months ago

I'm not a graphQL expert. Serialising this:

    type Token struct {
        IdToken      string `graphql:"id_token"`
        AccessToken  string `graphql:"access_token"`
        RefreshToken string `graphql:"refresh_token"`
        ExpiresIn    int    `graphql:"expires_in"`
    }

    var res struct {
        Token `graphql:"getAuthToken(code: $code)"`
    }

    if err := gqlClient.Query(context.Background(), &res, map[string]any{
        "code": code,
    }, graphql.OperationName("getAuthToken")); err != nil {
        return err
    }

yields

{"query":"query getAuthToken($code:String!){getAuthToken(code: $code){id_token,access_token,refresh_token,expires_in}}","variables":{"code":"EpNl5OrpZw36aKp5VSK7RUAr_FMz5UMAjhw29XFO"},"operationName":"getAuthToken"}

What strikes me strange is the commas between the field names- shouldn't that be spaces?

hgiasac commented 7 months ago

According to the GraphQL spec, spaces, commas, and newlines are all valid. The comma doesn't violate the spec https://spec.graphql.org/June2018/#sec-Source-Text.Ignored-Tokens