From 2ae468fe58fd9834cfd23d6478f63f6bf3206ccc Mon Sep 17 00:00:00 2001 From: Tyler Menezes Date: Mon, 8 Nov 2021 17:03:44 -0500 Subject: [PATCH] Add region resolver --- src/remotes/showcase.js | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/remotes/showcase.js b/src/remotes/showcase.js index 54e7c3f..ee7c62c 100644 --- a/src/remotes/showcase.js +++ b/src/remotes/showcase.js @@ -13,6 +13,7 @@ function getConnectionTypes(prefix) { extend type ${prefix}Project { eventGroup: CmsEvent program: CmsProgram + region: CmsRegion } extend type ${prefix}Award { @@ -86,6 +87,7 @@ function getConnectionResolvers(prefix, schemas) { program: { selectionSet: '{ programId }', async resolve(parent, args, context, info) { + if (!parent.programId) return null; return delegateToSchema({ schema: schemas.cms, operation: 'query', @@ -120,9 +122,11 @@ function getConnectionResolvers(prefix, schemas) { }); }, }, + eventGroup: { selectionSet: '{ eventGroupId }', async resolve(parent, args, context, info) { + if (!parent.eventGroupId) return null; return delegateToSchema({ schema: schemas.cms, operation: 'query', @@ -157,6 +161,45 @@ function getConnectionResolvers(prefix, schemas) { }); }, }, + + region: { + selectionSet: '{ regionId }', + async resolve(parent, args, context, info) { + if (!parent.regionId) return null; + return delegateToSchema({ + schema: schemas.cms, + operation: 'query', + fieldName: 'regionCollection', + args: { + where: { + webname: parent.regionId, + }, + limit: 1, + }, + context, + info, + transforms: [ + new TransformQuery({ + path: ['regionCollection'], + queryTransformer: (subtree) => ({ + kind: Kind.SELECTION_SET, + selections: [ + { + kind: Kind.FIELD, + name: { + kind: Kind.NAME, + value: 'items', + }, + selectionSet: subtree, + }, + ], + }), + resultTransformer: (r) => r?.items[0], + }), + ], + }); + }, + }, } }; }