Skip to content

Commit

Permalink
subgraph is optional on entities.many
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-sanfratello committed Dec 5, 2023
1 parent 7f185b5 commit 7cac9fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ main()
- `field` (string, optional) - The foreign key field.
- `as` (string, optional) - When using `addEntitiesResolvers`, it defines the name of the foreign entity as a field of the current one, as a single type.
- `pkey` (string, optional) - The primary key of the foreign entity.
- `subgraph` (string, optional) - The subgraph name of the foreign entity, where the resolver is located; if missing is intended the self.
- `resolver` (object, optional) - The resolver definition to query the foreing entity, same structure as `entity.resolver`.
- `many` (array of objects, optional) - Describe a 1-to-many relation - the reverse of the foreign key.
- `type` (string, required) - The entity type where the entity is a foreign key.
- `fkey` (string, required) - The foreign key field in the referred entity.
- `as` (string, required) - When using `addEntitiesResolvers`, it defines the name of the relation as a field of the current one, as a list.
- `pkey` (string, optional) - The primary key of the referred entity.
- `subgraph` (string, required) - The subgraph name of the referred entity.
- `subgraph` (string, optional) - The subgraph name of the referred entity, where the resolver is located; if missing is intended the self.
- `resolver` (object, required) - The resolver definition to query the referred entity, same structure as `entity.resolver`.
- `onSubgraphError` (function, optional) - Hook called when an error occurs getting schema from a subgraph. The default function will throw the error. The arguments are:
- `error` (error) - The error.
Expand Down
6 changes: 5 additions & 1 deletion lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ class Composer {

for (let k = 0; k < many.length; ++k) {
const m = many[k]
for (const p of ['type', 'fkey', 'as', 'pkey', 'subgraph']) {
for (const p of ['type', 'fkey', 'as', 'pkey']) {
validateString(m[p], `subgraphs[${subgraphName}].entities.${name}.many[${k}].${p}`)
}
for (const p of ['subgraph']) {
if (!m[p]) { continue }
validateString(m[p], `subgraphs[${subgraphName}].entities.${name}.many[${k}].${p}`)
}
validateResolver(m.resolver, `subgraphs[${subgraphName}].entities.${name}.many[${k}].resolver`)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "lib/index.js",
"author": "Colin J. Ihrig <[email protected]> (http://www.cjihrig.com/)",
"scripts": {
"test": "npm run lint && c8 node test/runner.js",
"test": "npm run lint && c8 node --test test/runner.js",
"lint": "standard | snazzy",
"lint:fix": "standard --fix"
},
Expand Down

0 comments on commit 7cac9fa

Please sign in to comment.