99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.92k stars 1.16k forks source link

support variables or not? #881

Closed coderbradlee closed 5 years ago

coderbradlee commented 5 years ago

What happened?

using variables,but actual value is not passed:

query Query($address:String!){
  x{
    byAddress(address: $address){
    }
    }
  }
}
 { "address": "xxxxx"} 

passed address is "$address",not "xxxxx"

What did you expect?

address="xxxxx"

Minimal graphql.schema and models to reproduce

versions

does this version support variables or not,or need users to parse? where can find an example?

vektah commented 5 years ago

It should, we use variables everywhere. Are you running a gqlgen server or calling the parser directly?

coderbradlee commented 5 years ago

a gqlgen server

a gqlgen server,can you give me an example for gqlgen parse variables ?I use graphql.CollectFieldsCtx and graphql.CollectFields cannot get the right value

vektah commented 5 years ago

Why do you need to use CollectFields? It's a low-level API that should only be needed for special cases like ORM field optimizations.

Resolvers should get their arguments as simple params, eg the id here: https://github.com/99designs/gqlgen/blob/master/example/todo/todo.go#L76

Have you read https://github.com/99designs/gqlgen#how-do-i-prevent-fetching-child-objects-that-might-not-be-used? I think that might be whats tripping you up.

coderbradlee commented 5 years ago

It's recursived schema: type Query { account: Account } type Account { activeAccounts(count: Int!): [String!] alias(operatorAddress: String!): Alias operatorAddress(aliasName: String!): OperatorAddress }

change gqlgen.yml could work for this kind of schema? gqlgen.yml models: User: fields: friends: resolver: true # force a resolver to be generated

vektah commented 5 years ago

Yep, you want a resolver for anything that goes back to the database.