在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graphitejs/server开源软件地址(OpenSource Url):https://github.com/graphitejs/server开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Framework NodeJS for GraphQl GraphiteJS is a NODE.JS Framework for building GraphQL schemas/types fast, easily and with scalability.
GuideInstallnpm i @graphite/server --save
yarn add @graphite/server
on your index file: import { Graphite } from '@graphite/server'
main = async () => {
const graphite = await Graphite()
}
main() and that's all, you have running the graphqli tool on the port 4000 by default. How to useAfter install Typesimport { GraphQL } from '@graphite/server'
export const Developer = GraphQL('Developer')({
// the value always have to be an array first arg is the type, the second arg is an optional comment
name: ['String!', 'Your name is required'],
age: ['Int'],
isGreatDeveloper: ['Boolean']
}) So, now you need to pass this model to the Graphite Server on import { Graphite } from '@graphite/server'
import { Developer } from './models/Developer'
main = async () => {
await Graphite({ models: [Developer] })
}
main() Queriesimport { GraphQL } from '@graphite/server'
export const Developer = GraphQL('Developer')({
name: ['String!', 'Your name is required'],
age: ['Int'],
isGreatDeveloper: ['Boolean'],
Query: {
'developer: Developer': () => ({ name: 'Your name' }),
'developers: [Developer]': () => ([{ name: 'Your name' }]),
}
}) Mutationsimport { GraphQL } from '@graphite/server'
export const Developer = GraphQL('Developer')({
name: ['String!', 'Your name is required'],
Mutation: {
'createDeveloper(name: String): Developer': (_, { name, }) => ({ name }),
'updateDeveloper(id: ID!, name: String): Developer': (_, { name }) => ({ name }),
'removeDeveloper(id: ID!): Developer': (_, { name }) => ({ name }),
},
}) Subscriptionsimport { GraphQL, PubSub } from '@graphite/server'
const pubsub = new PubSub()
const DEVELOPER_ADDED = 'DEVELOPER_ADDED'
export const Developer = GraphQL('Developer')({
name: ['String!', 'Your name is required'],
Mutation: {
'createDeveloper(name: String): Developer': (_, { name, }) => {
pubsub.publish(DEVELOPER_ADDED, { developerAdded: { name } })
return { name }
},
},
Subscription: {
'developerAdded: Developer': {
subscribe: () => pubsub.asyncIterator([DEVELOPER_ADDED]),
},
},
}) Relations // models/Repository.js
const Repository = GraphQL('Repository')({
name: ['String'],
url: ['String'],
})
// models/GithubProfile.js
const GithubProfile = GraphQL('GithubProfile')({
url: ['String'],
})
// models/Developer.js
const Developer = GraphQL('Developer')({
name: ['String'],
'respositories: [Repository]': () => [{ name: 'GraphiteJS', url: 'https://github.com/graphitejs/graphitejs' }],
'githubProfile: GithubProfile': () => ({ url: 'https://github.com/wzalazar' }),
Query: {
'developer: Developer': () => ({ name: 'Walter Zalazar' }),
},
}) So, now you need to pass this model to the Graphite Server on import { Graphite } from '@graphite/server'
import { Developer } from './models/Developer'
import { Repository } from './models/Repository'
import { GithubProfile } from './models/GithubProfile'
main = async () => {
await Graphite({ models: [Developer, Repository, GithubProfile] })
}
main() ContributingPlease see our contributing.md
npm install
TeamCreator
全部评论
专题导读
热门推荐
热门话题
阅读排行榜
|
请发表评论