question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validate AppSync Code-First GraphQL Schema before deploying

See original GitHub issue

I am using the code-first approach to constructing my GraphQL schema with @aws-cdk/aws-appsync. I have noticed that the schemas errors are really vague when pushing new schema changes via CDK.

E.G the last error I got was: Schema Creation Status is FAILED with details: Failed to parse schema document - ensure it's a valid SDL-formatted document.

I would love to be able to validate the schema before deployment or even print / save the schema to file as a test run. Its sometimes hard to spot mistakes when you are composing your schema using multiple files.

Use Case

We use AWS CDK and App Sync to build our GraphQL API. We need to be able to write the GraphQL schema reliably and test it before deploys.

Current Workaround

Currently, I am doing a console.log() of the schema during deployment to try and spot issues.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
BryanPan342commented, May 6, 2021

This feature is a big part of the appsync experience (esp the code-first).

Currently, I’m thinking we would have to run a check on synthesis after the entire gql string is built out… Speaking top of mind, there are two parts to this issue: syntax and semantics.

The code-first model should protect against most syntactical errors. Since we are generating most of the actual output itself, as long as the construct isn’t generating bad code, our syntax issues should be assuaged. I’m sure there are probably some issues here and there that need to be resolved to make it more robust, but in theory, the code-first model should save us from syntax errors.

As for the more semantic problems, I think the graphql library itself has a ton of great resources for this.

@MrArnoldPalmer how well-received would it be to add another package to the CDK dependencies?


EDIT

After looking into the graphql validation utilities , I think this is looking pretty good. In fact, I think the code snippet for this would be something along the lines of:

import {validate, parse, buildSchema} from 'graphql';

...
function validateSchema(schema: string) {
  const _schema = buildSchema(schema);
  const _ast = parse(schema)
  const errors = validate(_schema, _ast);

  if (errors) {
    errors.map((error) => throw new Error(error);
  }
}

No guarantees this would work outside of the box, but it seems promising 😊

3reactions
MrArnoldPalmercommented, May 6, 2021

@BryanPan342 I think it would be received fine for this case. Definitely seems like something we prioritize 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate GraphQL schema before deploying #104 - GitHub
I ran into an issue where I was using input types in my output types (obviously wrong) but I did not figure this...
Read more >
aws-cdk/aws-appsync module - AWS Documentation
Every GraphQL Api needs a schema to define the Api. CDK offers appsync.Schema for static convenience methods for various types of schema declaration:...
Read more >
Schema-First vs Code-Only GraphQL
When creating a GraphQL server there are two artifacts required by the GraphQL engine: a schema, which defines all the types and fields, ......
Read more >
GraphQL Code Libraries, Tools and Services
A collection of utility functions for building your own GraphQL HTTP server. You can check out Building a GraphQL server with GraphQL Helix...
Read more >
How to retrieve the schema.graphql file from @aws-cdk/aws ...
For Typescript code generation purposes I need a way to retrieve the schema.graphql before deployment (maybe somehow extracting it from the cdk ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found