At this point, your GraphQL API is able to fetch Meetup.com Groups filtered by their name as their list of events. You would want to go further and fetch the RSVPs of those events as well.
Meetup.com API does append that data to the payload we fetched for getting Events data. Instead, it provides another endpoint that brings you data about RSVPs.
Let's add some new types. As before, you can take a look to the model located in the github.com/smoya/graphql-go-workshop/pkg/meetup package.
Add the following types:
type Rsvp {
created: String!
updated: String!
response: String!
guests: Int
member: Member!
}
enum RsvpResponse{
yes
no
}
type Member {
id: Int!
name: String!
isHost: Boolean!
}
Add the following field to the Event
type:
rsvp(response: RsvpResponse): [Rsvp]
Before generating the code again, we would need to add few new lines to the gqlgen.yaml
file.
Please add the following lines under model
.
Rsvp:
model: github.com/smoya/graphql-go-workshop/pkg/meetup.RSVP
Member:
model: github.com/smoya/graphql-go-workshop/pkg/meetup.Member
Note The
resolver.go
file is generated only when the file is not present.
As the generator will end creating new Resolvers, you would need to choose 1 option from:
- Moving the
resolver.go
file to aresolver.go.copy
before executinggqlgen
for later "copy and paste" the needed code to the generated code. - Removing the
resolver.go
file and redo all the previous steps.
gqlgen
would generate a new method on the eventResolver
called Rsvp
.
Use the Meetup.com client for fetching data about the RSVP of such event
func (r *eventResolver) Rsvp(ctx context.Context, obj *meetup.Event, response *RsvpResponse) ([]*meetup.RSVP, error) {
return r.C.RSVPs(obj.Group.Urlname, obj.ID, (*string)(response))
}
gqlgen
would generate a new resolver called rsvpResolver
.
You would need to implement some methods:
func (r *rsvpResolver) Created(ctx context.Context, obj *meetup.RSVP) (string, error) {
return time.Unix(obj.Created/1000, 0).Format(time.RFC822), nil
}
func (r *rsvpResolver) Updated(ctx context.Context, obj *meetup.RSVP) (string, error) {
return time.Unix(obj.Updated/1000, 0).Format(time.RFC822), nil
}
func (r *rsvpResolver) Response(ctx context.Context, obj *meetup.RSVP) (RsvpResponse, error) {
return RsvpResponse(obj.Response), nil
}
Run go run server/server.go
.
Open your browser and navigate to http://localhost:8080.
Execute the following query:
{
group(name: "Golang-Barcelona") {
name
events(status: upcoming) {
name
rsvp(response: no) {
member {
name
}
response
created
updated
}
}
}
}