Skip to content

Instantly share code, notes, and snippets.

@vniche
Created March 9, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vniche/055f5cea3e0f60185d1b071b0b59394a to your computer and use it in GitHub Desktop.
Save vniche/055f5cea3e0f60185d1b071b0b59394a to your computer and use it in GitHub Desktop.
Implemented endpoints for Getting Started with GraphQL + Golang (in 5 minutes)
...
func (r *mutationResolver) Signup(ctx context.Context, input NewUser) (string, error) {
user := &User{
ID: uuid.New().String(),
Name: input.Name,
Surename: input.Surename,
CreatedAt: time.Now().String(),
}
// removes oldest user if users length is over 30
if len(Users) > 30 {
Users = Users[1:29]
}
// appends new user to global (in-memory) users list
Users = append(Users, user)
return user.ID, nil
}
func (r *queryResolver) User(ctx context.Context, ID string) (*User, error) {
var user *User
for _, current := range Users {
if current.ID == ID {
user = current
}
}
return user, nil
}
func (r *queryResolver) Users(ctx context.Context) ([]*User, error) {
return Users, nil
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment