在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):AEB-labs/cruddl开源软件地址(OpenSource Url):https://github.com/AEB-labs/cruddl开源编程语言(OpenSource Language):TypeScript 93.5%开源软件介绍(OpenSource Introduction):cruddlcruddl - create a cuddly GraphQL API for your database, using the GraphQL SDL to model your schema. This TypeScript library creates an executable GraphQL schema from a model definition and provides queries and mutations to access a database. Currently, it supports the multi-model database ArangoDB. The concept being inspired by existing projects like prisma and join-monster, cruddl exploits the expressiveness of the Arango Query Language (AQL) to generate one tailored query for each GraphQL request. Features
Usage
Install ArangoDB and create a new database. import { ArangoDBAdapter } from 'cruddl';
const db = new ArangoDBAdapter({
databaseName: 'databaseName',
url: 'http://root:@localhost:8529',
user: 'root',
password: ''
}); If you just want to explore the features, you can also use an in-memory database implementation - but don't use this for anything else. import { InMemoryAdapter } from 'cruddl';
const db = new InMemoryAdapter(); Define your data model and create a project: import { Project } from 'cruddl';
const project = new Project({
sources: [
{
name: 'schema.graphqls',
body: `
type Movie @rootEntity {
title: String
actors: Actor @relation
}
type Actor @rootEntity {
name: String
movies: Movie @relation(inverseOf: "actors")
}`
},
{
name: 'permission-profiles.json',
body: JSON.stringify({
permissionProfiles: {
default: {
permissions: [
{
roles: ['users'],
access: 'readWrite'
}
]
}
}
})
}
],
getExecutionOptions: ({ context }) => ({ authRoles: ['users'] }),
getOperationIdentifier: ({ context }) => context as object // each operation is executed with an unique context object
}); Then, create the GraphQL schema and serve it: import { ApolloServer } from 'apollo-server';
const schema = project.createSchema(db);
db.updateSchema(project.getModel()); // create missing collections
const server = new ApolloServer({
schema,
context: ({ req }) => req // pass request as context so we have a unique context object for each operation
});
server.listen(4000, () => console.log('Server is running on http://localhost:4000/')); See the modelling guide and the api documentation for details. Usage in a browser environmentThe core of cruddl perfectly works in a browser (e.g., using webpack), and this can be useful to generate a mock GraphQL schema on the fly or to validate a cruddl project. However, the ArangoDB adapter only works with node imports like Running TestsFor consistency, tests shall be run against a single arangodb node:
When done, stop the instance with Documentation |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论