在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):brysgo/graphql-bookshelf开源软件地址(OpenSource Url):https://github.com/brysgo/graphql-bookshelf开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):GraphQL + BookshelfJSThis is an early version of the Install
...
Example use...Use export default new GraphQLObjectType(BookshelfType({
name: 'Classroom',
description: 'Need I say more?',
// ...and an object gets passed into the fields to help with your model.
fields: (model) => ({ Simply wrap with id: model.attr({
type: new GraphQLNonNull(GraphQLInt),
description: 'The id of the classroom.',
// ...and you don't need to resolve table attributes.
}), Or wrap with model.belongsTo()... subject: model.belongsTo({
type: SubjectType, // And use the right association type...
description: 'The subject of the classroom.',
// And you get one-to-one relationships for free
}), Use model.hasMany()... students: model.hasMany({
type: new GraphQLList(StudentType), // And make sure you use `GraphQLList`
description: 'Students in the classroom.',
// Now you have associated collections for free
}), Need to do more on your associated collection? homeworks: model.hasMany({
type: new GraphQLList(HomeworkType),
description: 'Homework submitted to the classroom (latest to oldest).',
// Define a resolve function...
resolve: (qb) => {
// And get a sweet KnexJS query builder
qb.orderBy('created_at', 'DESC');
}
}), Or just leave it alone... size: {
type: GraphQLInt,
description: 'How many students there are in the class.',
resolve: (model) => {
// And do it the old fashioned way
return model.studentCount();
},
}
}),
})); Are you using graphql-relay-js? Define some connection associations. At the top: import { connectionDefinitions, connectionArgs } from "graphql-relay"; And in your schema... homeworks: model.hasMany({
type: connectionDefinitions({nodeType: HomeworkType}).connectionType,
args: connectionArgs,
description: 'Homework submitted to the classroom.'
}), Goals & PhilosophyThis library is intended to keep it simple. Automatic generation of schema can leave use-cases out, while using bookshelf in every resolve calls for large amounts of repetitive boilerplate. Another thing this library could help with is optimization. Turing graphql queries into database calls can be expensive, but using a layer in between can help make those optimizations that would get ugly and repetitive in every resolve. See this example in action via the tests... Contributing
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论