Last active
April 18, 2019 17:47
-
-
Save motephyr/7dacb6df3aa805d421060af2b378f21e to your computer and use it in GitHub Desktop.
graphql file struct.
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
//-----types.graphql | |
type Post { | |
id: Int | |
user_id: Int | |
title: String | |
description: String | |
created_at: Date | |
updated_at: Date | |
} | |
type User { | |
id: Int | |
username: String | |
password: String | |
created_at: Date | |
updated_at: Date | |
} | |
type Query { | |
users: [User] | |
user(id: Int!): User | |
posts: [Post] | |
post(id: Int!): Int | |
} | |
//------resolver.js | |
const resolvers = { | |
... | |
async users() { | |
const users = await User.all() | |
return users.toJSON() | |
}, | |
// Get a user by its ID | |
async user(_, { id }) { | |
const user = await User.find(id) | |
return user.toJSON() | |
} | |
async posts() { | |
const posts = await Post.all() | |
return posts.toJSON() | |
}, | |
// Get a user by its ID | |
async post(_, { id }) { | |
const post = await Post.find(id) | |
return post.toJSON() | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment