Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created July 8, 2019 10: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 daniele-zurico/1a00fafc72c09042fa2613680712bd48 to your computer and use it in GitHub Desktop.
Save daniele-zurico/1a00fafc72c09042fa2613680712bd48 to your computer and use it in GitHub Desktop.
const {gql} = require('apollo-server');
const typeDefs = gql`
extend type Query {
book(id: ID!): Book
books: [Book]
}
type Book {
id: ID!
title: String
author: Author
}
extend type Author {
books: [Book]
}
`;
const resolvers = {
Query: {
book(_, {id}) {
return {
id,
title: 'test',
author: {
id: Math.round(Math.random() * 100000),
name: 'Daniele',
surname: 'Zurico'
}
}
},
books() {
return [
{
id: Math.round(Math.random() * 100000),
title: 'test',
author:{
id: Math.round(Math.random() * 100000),
name: 'Daniele',
surname: 'Zurico'
}
},
{
id: Math.round(Math.random() * 100000),
title: 'test2',
author: {
id: Math.round(Math.random() * 100000),
name: 'Alex',
surname: 'Michaels'
},
}
]
}
},
Author: {
books() {
return [{
id: Math.round(Math.random() * 100000),
title: 'test',
}]
}
}
};
module.exports = {
typeDefs,
resolvers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment