Skip to content

Instantly share code, notes, and snippets.

@vniche
Created March 9, 2020 01:16
Show Gist options
  • Save vniche/93ebbb8ee8e27cab6148038e23779122 to your computer and use it in GitHub Desktop.
Save vniche/93ebbb8ee8e27cab6148038e23779122 to your computer and use it in GitHub Desktop.
Global in-memory storage for GraphQL in Golang
...
"github.com/artemis-tech/sample-graph/graph"
)
func main() {
port := "3030"
if os.Getenv("PORT") != "" {
port = os.Getenv("PORT")
}
// initializes graph package global Users variable with 0 entries and capacity of 30
graph.Users = make([]*graph.User, 0, 30)
http.Handle("/graphql/playground", handler.Playground("GraphQL playground", "/query"))
...
...
type Resolver struct{}
// Users stands for the in-memory list of users
var Users []*User
func (r *mutationResolver) Signup(ctx context.Context, input NewUser) (string, error) {
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment