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.

spectaQL directive breaks the GQL server when it's not defined

See original GitHub issue

I’m trying to implement spectaQL for our orgs graphql server. I’m having quite a bit of trouble with getting any approach to adding metadata in. My preferred method would be to use the spectaQL directive as then I can add my documentation right in my schema, but the part I’m not understanding is that adding an undefined directive to your schema will break the server

/opt/myorg/node_modules/graphql/validation/validate.js:108
    throw new Error(errors.map(function (error) {
          ^
Error: Unknown directive "spectaql".

Unknown directive "spectaql".
    at assertValidSDL (/opt/myorg/node_modules/graphql/validation/validate.js:108:11)
    at Object.buildASTSchema (/opt/myorg/node_modules/graphql/utilities/buildASTSchema.js:71:34)
    at Object.buildSchemaFromTypeDefinitions (/opt/myorg/node_modules/apollo-server-express/node_modules/graphql-tools/src/generate/buildSchemaFromTypeDefinitions.ts:43:32)
    at Object.makeExecutableSchema (/opt/myorg/node_modules/apollo-server-express/node_modules/graphql-tools/src/makeExecutableSchema.ts:52:16)
    at ApolloServer.initSchema (/opt/myorg/node_modules/apollo-server-express/node_modules/apollo-server-core/src/ApolloServer.ts:493:27)
    at new ApolloServerBase (/opt/myorg/node_modules/apollo-server-express/node_modules/apollo-server-core/src/ApolloServer.ts:356:26)
    at new ApolloServer (/opt/myorg/node_modules/apollo-server-express/src/ApolloServer.ts:88:5)
    at Object.<anonymous> (/opt/myorg/app/src/index.ts:122:16)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Module.m._compile (/opt/myorg/node_modules/ts-node/src/index.ts:858:23)
[nodemon] app crashed - waiting for file changes before starting...

I’ve tried defining the directive in my schema as well:

    input SpectaQLOption {
        key: String!
        value: String!
    }
    directive @spectaql(options: [SpectaQLOption]) on FIELD_DEFINITION

and this also doesn’t seem to get picked up when running spectaql. This is how I’m using the directive

    """this is documented"""
    type MyType {
        myField: String! @spectaql(options: [{ key: "example", value: "it looks like this" }]. # this is not generating anything with spectaQL)
        "this is anotherfield, which is documented and picked up by spectaQL"
        anotherField: String!
    }

The spectaQL docs say that it’s unnecessary to define the directive yourself, so I’m quite lost as to how that’s possible. As well as to why spectaQL isn’t picking up on the directive once it’s defined.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
newhousecommented, Nov 4, 2022

Hi @jason-dahl I understand the use-case here and will have a look ASAP. I’m surprised to hear it’s not having an effect when you define the directive yourself in your SDL, but I’ll figure it out and get back to you.

0reactions
elijaholmoscommented, Nov 28, 2022

@newhouse the first suggestion worked, thank you 🙂 I like how it can be done programmatically for my SDL generation, and I may use that as my project progresses. thank you for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expose user-defined meta-information via introspection API in ...
I would rather define a directive as a way to provide additional structured information on different GraphQL entities. Server and clinet runtime ...
Read more >
GraphQL schema basics - Apollo GraphQL Docs
Your GraphQL server uses a schema to describe the shape of your available data. This schema defines a hierarchy of types with fields...
Read more >
Keeping certain parts of your GraphQL schema hidden from ...
In this post, I will talk about how to leverage custom GraphQL Directives to hide sensitive things from the Introspection Query results so...
Read more >
GraphQL Code Libraries, Tools and Services
Simply declare your data requirements using GraphQL and let Relay figure out how and ... A set of libraries for running GraphQL client...
Read more >
spectaql - npm
SpectaQL does not need you to add the definition of the spectaql directive, nor its SpectaQLOption input type to your SDL.
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