Skip to content

Docs for GQL query and mutation aliases #691

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

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion _includes/graphql/customisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,21 @@ interface ParseGraphQLConfiguration {
query?: {
get?: boolean;
find?: boolean;
getAlias?: String;
findAlias?: String;
};

// By default, all write mutation types are
// exposed for all included classes. Use this to disable
// the available mutation types for this class.
// the available mutation types for this class and optionally
// override the default generated name with aliases.
mutation?: {
create?: boolean;
update?: boolean;
destroy?: boolean;
createAlias?: String,
updateAlias?: String,
destroyAlias?: String,
};
}>
}
Expand Down Expand Up @@ -214,6 +220,27 @@ By default, the schema exposes a `get` and `find` operation for each class, for
}
```

By default, generated query names use pluralized version of `className`. You can override this behaviour with `getAlias`/`findAlias`. This is useful when your collection is named in plural or when singular/plural forms are same e.g. `Data`:

```javascript
{
"classConfigs": [
{
"className": "Likes",
"query": {
"getAlias": "like"
}
},
{
"className": "Data",
"query": {
"findAlias": "findData"
}
}
]
}

```
### Mutations

By default, the schema exposes a `create`, `update` and `delete` operation for each class, for example, `create_User`, `update_User` and `delete_User`. You can disable any of these mutations for any class in your schema, like so:
Expand Down Expand Up @@ -243,3 +270,20 @@ By default, the schema exposes a `create`, `update` and `delete` operation for e
```

**Note**: the `delete` mutation setting key is named `destroy` to avoid issues due to `delete` being a javascript reserved word.

You can optionally override the default generated mutation names with aliases:

```javascript
{
"classConfigs": [
{
"className": "Record",
"mutation": {
"createAlias": "newRecord",
"updateAlias": "changeRecord",
"destroyAlias": "eraseRecord"
}
}
]
}
```