Skip to content

Commit

Permalink
fix and actually introduce dynamic selection sets (#1798)
Browse files Browse the repository at this point in the history
fix typos! add tests!
  • Loading branch information
yaacovCR committed Jul 19, 2020
1 parent 479892b commit 9a6aeb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/stitch/src/stitchingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ export function completeStitchingInfo(stitchingInfo: StitchingInfo, resolvers: I
const field = type[fieldName] as IFieldResolverOptions;
if (field.selectionSet) {
if (typeof field.selectionSet === 'function') {
if (!(typeName in selectionSetsByField)) {
if (!(typeName in dynamicSelectionSetsByField)) {
dynamicSelectionSetsByField[typeName] = Object.create(null);
}

if (!(fieldName in selectionSetsByField[typeName])) {
if (!(fieldName in dynamicSelectionSetsByField[typeName])) {
dynamicSelectionSetsByField[typeName][fieldName] = [];
}

Expand Down
12 changes: 11 additions & 1 deletion packages/stitch/tests/alternateStitchSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
GraphQLFieldConfig,
isSpecifiedScalarType,
GraphQLNamedType,
Kind,
} from 'graphql';

import {
Expand Down Expand Up @@ -216,7 +217,16 @@ describe('merge schemas through transforms', () => {
},
Bookings_Booking: {
property: {
selectionSet: '{ propertyId }',
selectionSet: () => ({
kind: Kind.SELECTION_SET,
selections: [{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: 'propertyId',
}
}]
}),
resolve: (parent, _args, context, info) =>
delegateToSchema({
schema: propertySubschema,
Expand Down

0 comments on commit 9a6aeb4

Please sign in to comment.