Last active
September 7, 2018 13:46
-
-
Save timoweiss/940025e301cd43a5954005df9f5489de to your computer and use it in GitHub Desktop.
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
/** | |
graphql sample query: | |
{ | |
event(eventId: "123") { | |
days | |
eventItems { | |
id | |
day | |
} | |
} | |
*/ | |
/** | |
graphql schema | |
type Query { | |
event(eventId: String!): Event | |
happening(happendingId: String!): Happening | |
} | |
type Event { | |
id: String! | |
# unique list of days an eventItem exists for | |
days: [String] | |
eventItems: [EventItem] | |
} | |
type Happening { | |
id: String! | |
description: String | |
eventItems: [EventItem] | |
} | |
*/ | |
const RootResolvers = { | |
event(_, args, ctx, info) { | |
// option 1: query eventItems here and return them to the child resolver "eventItems" and "days" | |
// option 2: pass down eventId to let the child resolver "eventItems" and "days" fetch the data | |
// pro | |
// option 1: eventItems are fetched only once and reused for eventItems + days | |
// option 2: logic of how eventItems are fetched is hidden in eventItems resolver and can be reused (eventItems of happening) | |
// option 2: child resolvers are only invoked if queried | |
// contra | |
// option 1: to not unnecessarily fetch eventItems, the info object needs to be parsed to find out if eventItems/days is queried | |
// option 1: fetching of eventItems need to be implemented in other (parent) resolvers if necessary | |
// option 2: if days and eventItems are queried, both resolvers need to fetch the same data to calc its result | |
}, | |
happening(_, args, ctx, info) {} | |
} | |
const Event = { | |
id(parent, args, ctx, info) {}, | |
days(parent, args, ctx, info) {}, | |
eventItems(parent, args, ctx, info) {} | |
} | |
const Happening = { | |
id(parent, args, ctx, info) {}, | |
description(parent, args, ctx, info) {}, | |
eventItems(parent, args, ctx, info) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment