Created
July 8, 2019 10:11
-
-
Save daniele-zurico/1a00fafc72c09042fa2613680712bd48 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
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