Skip to content

[Feature] Add Support for Directive filters and Type filters to cover AWS AppSync use-cases#1143

Open
malikfaik wants to merge 2 commits intographql-nexus:mainfrom
malikfaik:main
Open

[Feature] Add Support for Directive filters and Type filters to cover AWS AppSync use-cases#1143
malikfaik wants to merge 2 commits intographql-nexus:mainfrom
malikfaik:main

Conversation

@malikfaik
Copy link
Copy Markdown

Problem Statement

Current implementation of custom directives and scalars always outputs a definition for the directive/scalar with the developer having no control over it. for e.g. defining aws_lambda directive for certain fields which is a inherently defined / supported directive by AWS App Sync but not by the GraphQL standard will output the directive definition which AWS does not like 🥲, making this library in all it's glory very hard to use with AppSync.

An example of the current output:

directive @aws_lambda on OBJECT

scalar AWSTimestamp

type Query {
  ok: Boolean!
}

type Random @aws_lambda {
  expiry: AWSTimestamp
}

What AWS AppSync would like the output to be:

type Query {
  ok: Boolean!
}

type Random @aws_lambda {
  expiry: AWSTimestamp
}

Fix

To work around the issue and to give more control to the developer I added another optional field to the makeSchema method called filters, which allows the developer to define custom filters for the directives and types which gives them the ability to exclude them from the definition if needed.

makeSchema({
  types: [],
  filters: {    // new config field introduced
    isEnvironmentDefinedDirective: (directive) => {
      return directive.name === 'aws_lambda'
    },
    isEnvironmentDefinedType: (type) => {
      return type.name === 'AWSTimestamp'
    },
  },
  outputs: {
    schema: pathToSchema,
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant