Created
December 26, 2019 12:53
-
-
Save danstarns/2cd0e6e14d51a07897268699450fef9b to your computer and use it in GitHub Desktop.
idio-graphql nested nodes gist
This file contains hidden or 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 { ApolloServer } = require("apollo-server"); | |
| const { combineNodes, GraphQLNode } = require("idio-graphql"); | |
| const gql = require("graphql-tag"); | |
| const User = new GraphQLNode({ | |
| name: "User", | |
| typeDefs: gql` | |
| type User { | |
| id: ID | |
| name: String | |
| age: Int | |
| } | |
| type Query { | |
| user(id: ID!): User | |
| } | |
| `, | |
| resolvers: { | |
| Query: { | |
| user: () => { } | |
| } | |
| } | |
| }); | |
| const Comment = new GraphQLNode({ | |
| name: "Comment", | |
| typeDefs: gql` | |
| type Comment { | |
| id: ID | |
| content: String | |
| User: User | |
| } | |
| type Query { | |
| comment(id: ID!): Comment | |
| } | |
| `, | |
| resolvers: { | |
| Query: { | |
| comment: () => { } | |
| } | |
| } | |
| }); | |
| const Post = new GraphQLNode({ | |
| name: "Post", | |
| typeDefs: gql` | |
| type Post { | |
| id: ID | |
| title: String | |
| content: Int | |
| comments: [Comment] | |
| } | |
| type Query { | |
| post(id: ID!): Post | |
| } | |
| `, | |
| resolvers: { | |
| Query: { | |
| post: () => { } | |
| } | |
| }, | |
| nodes: [Comment] | |
| }); | |
| async function main() { | |
| const { typeDefs, resolvers } = await combineNodes([User, Post]); | |
| const server = new ApolloServer({ typeDefs, resolvers }); | |
| await server.listen(4000); | |
| console.log(`Server up on port 4000 🚀`); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment