machinebox / graphql

Simple low-level GraphQL HTTP client for Go
https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878
Apache License 2.0
933 stars 218 forks source link

Post body missing #11

Closed kelvinji2009 closed 6 years ago

kelvinji2009 commented 6 years ago

Hi,

Sample code(Using default http client)

     req := graphql.NewRequest(`
        query {
            getAccessTokenByAppSecret(
                clientId: $clientID,
                secret: $appSecret
            )
        }
     `)

    req.Var("clientID", clientID)
    req.Var("appSecret", appSecret)

    ctx := context.Background()

    var responseData map[string]interface{}

    if err := c.userGraphqlClient.Run(ctx, req, &responseData); err != nil {
        log.Fatal(err)
    }

Log info

☆  examples  »go run main.go
2018/03/18 01:52:04 >> variables: {"appSecret":"5cf63e2b82f2d6b41bdcfec8b483b740","clientID":"5a48b6ae863b3b0001893bbc"}

2018/03/18 01:52:04 >> files: 0
2018/03/18 01:52:04 >> query:
        query {
            getAccessTokenByAppSecret(
                clientId: $clientID,
                secret: $appSecret
            )
        }

2018/03/18 01:52:04 >> headers: map[Content-Type:[multipart/form-data; boundary=f262269d26f9acbc6a727ad9e0becd29acbc33c1f0110691763f4cb54862] Accept:[application/json]]
2018/03/18 01:52:05 << POST body missing. Did you forget use body-parser middleware?
2018/03/18 01:52:05 decoding response: invalid character 'P' looking for beginning of value
exit status 1
matryer commented 6 years ago

Please update and try again following https://github.com/machinebox/graphql/pull/15.

kelvinji2009 commented 6 years ago

@matryer Great. It works now. Thanks a lot.