Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

malikfaik
Copy link

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