A schema is the structure behind data organization
type Query {
hero(episode: Episode): Character
droid(id: ID!): Droid
}
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
createReview(episode: $ep, review: $review) {
stars
commentary
}
}
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
type Character {
name: String!
appearsIn: [Episode]!
}
interface Character {
id: ID!
name: String!
}
type Human implements Character {
id: ID!
name: String!
starships: [Starship]
totalCredits: Int
}
type Droid implements Character {
id: ID!
name: String!
primaryFunction: String
}
union SearchResult = Human | Droid | Starship
{
search(text: "an") {
... on Human {
name
height
}
... on Droid {
name
primaryFunction
}
... on Starship {
name
length
}
}
}
input ReviewInput {
stars: Int!
commentary: String
}
schema {
query: Query
mutation: Mutation
}
type Character {
name: String!
appearsIn: [Episode]!
}
type Query {
hero(episode: Episode): Character
droid(id: ID!): Droid
}
const resolvers = {
Query: {
hero(root, args, context, info) {
return find(heroes, { id: args.id });
},
},
Character: {
appearsIn {
return filter(characterAppearsIn, { author: author.name });
},
},
};