Skip to content

Commit

Permalink
fix: PageInfo must define one or more fields
Browse files Browse the repository at this point in the history
Fixes a regression introduced in `v3.1`. `schemaComposer.createObjectTC` accepts a `typeDef`, which could be a `string` (as in https://github.com/graphql-compose/graphql-compose-elasticsearch/blob/v3.1.1/src/resolvers/searchConnection.js#L141). `cfg` does not have `field` attributes in this case, causing `PageInfo` to be empty.

Closes #60
  • Loading branch information
perrin4869 authored and nodkz committed Apr 9, 2019
1 parent 99e53e2 commit 372310a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,25 @@ export function prepareCommonOpts<TContext>(
schemaComposer,
getOrCreateOTC: (typeName, cfgOrThunk) => {
return schemaComposer.getOrSet(typeName, () => {
const tc = schemaComposer.createObjectTC(typeName);
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
tc.setFields(cfg.fields);
tc.setDescription(cfg.description);
const tc = schemaComposer.createObjectTC(
isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk
);
return tc;
});
},
getOrCreateITC: (typeName, cfgOrThunk) => {
return schemaComposer.getOrSet(typeName, () => {
const tc = schemaComposer.createInputTC(typeName);
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
tc.setFields(cfg.fields);
tc.setDescription(cfg.description);
const tc = schemaComposer.createInputTC(
isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk
);
return tc;
});
},
getOrCreateETC: (typeName, cfgOrThunk) => {
return schemaComposer.getOrSet(typeName, () => {
const tc = schemaComposer.createEnumTC(typeName);
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
tc.setFields(cfg.values);
tc.setDescription(cfg.description);
const tc = schemaComposer.createEnumTC(
isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk
);
return tc;
});
},
Expand Down

0 comments on commit 372310a

Please sign in to comment.