99designs / gqlgen

go generate based graphql server library

Home Page:https://gqlgen.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the best way to pass variables between query and response object field resolver ?

Sonovrik opened this issue · comments

What happened?

I want to know best practice to pass variables between query and response object field resolver.

What did you expect?

I need sync way for passing variables between query and response object field resolver.
I know about OperationContext, but it is basic map, so I have some concurrent problems.

tmp := "Hello world"
graphql.GetOperationContext(ctx).Variables["HelloWorld"] = &tmp
tmp2 := graphql.GetOperationContext(ctx).Variables["HelloWorld"].(*string)

Minimal graphql.schema and models to reproduce

Object {
  ID: ID!
  isOK: Boolean! @goField(forceResolver: true)
}

type Query {
  Objects: [Object!]
}

versions

  • go run github.com/99designs/gqlgen version 17.41
  • go version go1.19.2