graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.94k stars 841 forks source link

Is there any example to run a simple query against an existing schema using authentication? #659

Closed droslean closed 5 months ago

droslean commented 1 year ago

Is there any example to run a simple query against an existing schema using authentication?

Perhaps I misunderstood what is this library for. My goal is to run a simple query against my graphQL server programmatically using also a Bearer token for authentication.

I am trying to do


       query := `
query MyQuery {
  queryImage {
    id
  }
}
`
    params := graphql.Params{RequestString: query}
    r := graphql.Do(params)
    if len(r.Errors) > 0 {
        log.Fatalf("failed to execute graphql operation, errors: %+v", r.Errors)
    }
    rJSON, _ := json.Marshal(r)
    fmt.Printf("%s \n", rJSON)

The response is always empty.

droslean commented 1 year ago

@chris-ramon cc