Created
March 9, 2020 13:11
-
-
Save vniche/055f5cea3e0f60185d1b071b0b59394a to your computer and use it in GitHub Desktop.
Implemented endpoints for Getting Started with GraphQL + Golang (in 5 minutes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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