Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arangorizeSchema #15

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v1
Expand Down
67 changes: 55 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,6 @@ You may also need to install peer dependencies if you don't have them:
npm i --save graphql arangojs
```

### Directive type definitions

To use the directives in this library, you need to add type definitions for them. The library exports pre-built type definitions for all directives, you just need to include them in your type definitions.

```ts
import { directiveTypeDefs } from 'graphql-arangodb';

const typeDefs = [directiveTypeDefs, ...allYourAppsOtherTypeDefs];

makeExecutableSchema({ typeDefs });
```

### Adding a Database instance

The easiest way to connect `graphql-arangodb` to your ArangoDB database is to instantiate a `Database` class from `arangojs` and assign it to the `arangoDb` field of your GraphQL `context`:
Expand All @@ -129,6 +117,61 @@ const context = {
// pass the context into your GraphQL server according to documentation of the server
```

### Directive type definitions

To use the directives in this library, you need to add type definitions for them. The library exports pre-built type definitions for all directives, you can either include them manually,

```ts
import { directiveTypeDefs } from 'graphql-arangodb';

const typeDefs = [directiveTypeDefs, ...allYourAppsOtherTypeDefs];

makeExecutableSchema({ typeDefs });
```

or you can use the arangorizeSchema generator. arangorizeSchema can additionaly automatically create document and edge collections and indexes:

Schema example:

```graphql
type User @aqlCollection(name: "users" ) {
id: String! @aqlIndex(type: UNIQUE)
name: String!
friends: [FriendOfEdge!]!
@aqlEdge(
collection: "friendOf"
direction: ANY
sort: { property: "name", sortOn: "$field_node" }
)
}

@aqlCollection(name: "friendOf", type: EDGE )
type FriendOfEdge {
strength: Int
user: User! @aqlEdgeNode
}
```

```TS
import { arangorizeSchema } from 'graphql-arangodb';

const typeDefs = [...allYourAppsOtherTypeDefs];
const resolvers = { ...allYourResolvers}

await arangorizeSchema({ typeDefs, resolvers }, db );
```

As an optional, last parameter you can add a database name when you want to ensure a database exisits. If the database does not exists it will be created.

```TS
import { arangorizeSchema } from 'graphql-arangodb';

const typeDefs = [...allYourAppsOtherTypeDefs];
const resolvers = { ...allYourResolvers}

await arangorizeSchema({ typeDefs, resolvers }, db, 'myAwesomeDB');
```

### Resolvers

To start resolving queries using AQL, you need to set up resolvers for fields which will be resolved using those queries. For most use cases, this means all of the top-level fields in the root query and mutation types.
Expand Down
Loading