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.

Unknown argument "includeDeprecated" on field "__Directive.args"

See original GitHub issue

With the update to 15.5.0, we need to implement our own script to fetch the GraphQL schema (get-graphql-schema that we were using doesn’t seem to be maintained anymore).

I’m using the following script to achieve that:

npm run script scripts/update-graphql-schemas.ts http://localhost:3060/graphql/v1
// scripts/update-graphql-schemas.ts

import * as fs from 'fs';
import * as path from 'path';

import { buildClientSchema } from 'graphql/utilities/buildClientSchema';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery';
import { printSchema } from 'graphql/utilities/printSchema';
import fetch from 'node-fetch';

interface Options {
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
  headers?: { [key: string]: string };
  json?: boolean;
}

/**
 *
 * Fetch remote schema and turn it into string
 *
 * @param endpoint
 * @param options
 */
export async function getRemoteSchema(
  endpoint: string,
  options: Options,
): Promise<{ status: 'ok'; schema: string } | { status: 'err'; message: string }> {
  try {
    const introspectionQuery = getIntrospectionQuery({ inputValueDeprecation: true });
    const { data, errors } = await fetch(endpoint, {
      method: options.method,
      headers: options.headers,
      body: JSON.stringify({ query: introspectionQuery }),
    }).then(res => res.json());

    if (errors) {
      return { status: 'err', message: JSON.stringify(errors, null, 2) };
    }

    if (options.json) {
      return {
        status: 'ok',
        schema: JSON.stringify(data, null, 2),
      };
    } else {
      const schema = buildClientSchema(data);
      return {
        status: 'ok',
        schema: printSchema(schema),
      };
    }
  } catch (err) {
    return { status: 'err', message: err.message };
  }
}

/**
 *
 * Prints schema to file.
 *
 * @param dist
 * @param schema
 */
export function printToFile(
  dist: string,
  schema: string,
): { status: 'ok'; path: string } | { status: 'err'; message: string } {
  try {
    const output = path.resolve(process.cwd(), dist);

    if (!fs.existsSync(output)) {
      console.error(`${output} does not exists`);
      process.exit(1);
    }
    fs.writeFileSync(output, schema);

    return { status: 'ok', path: output };
  } catch (err) {
    return { status: 'err', message: err.message };
  }
}

export async function main(endpoint): Promise<void> {
  /* Headers */
  const defaultHeaders = {
    'Content-Type': 'application/json',
  };

  /* Fetch schema */
  const schema = await getRemoteSchema(endpoint, {
    method: 'POST',
    headers: defaultHeaders,
    json: false,
  });

  if (schema.status === 'err') {
    console.error(schema.message);
  } else {
    console.log(schema.schema);
  }
}

main(process.argv[2]);

This script works fine without inputValueDeprecation: true passed to getIntrospectionQuery, but whenever I try to add this option the script fails with the following message:

[
  {
    "message": "Unknown argument \"includeDeprecated\" on field \"__Directive.args\".",
    "locations": [
      {
        "line": 16,
        "column": 16
      }
    ],
    "extensions": {
      "code": "GRAPHQL_VALIDATION_FAILED",
      "exception": {
        "stacktrace": [
          "GraphQLError: Unknown argument \"includeDeprecated\" on field \"__Directive.args\".",
          "    at Object.Argument (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/graphql/validation/rules/KnownArgumentNamesRule.js:46:29)",
          "    at Object.enter (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/graphql/language/visitor.js:323:29)",
          "    at Object.enter (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/graphql/utilities/TypeInfo.js:370:25)",
          "    at visit (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/graphql/language/visitor.js:243:26)",
          "    at Object.validate (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/graphql/validation/validate.js:69:24)",
          "    at validate (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/apollo-server-core/src/requestPipeline.ts:510:14)",
          "    at Object.<anonymous> (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/apollo-server-core/src/requestPipeline.ts:296:32)",
          "    at Generator.next (<anonymous>)",
          "    at fulfilled (/home/user/Workspace/Projects/opencollective/opencollective-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
          "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
        ]
      }
    }
  }
]

Context

Followup on https://github.com/graphql/graphql-js/issues/2834

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
davidgoveacommented, Apr 27, 2021

Added a PR #3046 with a test that reproduces this issue. Also attempted a fix, but I don’t think I used the correct approach (removed includeDeprecated from __schema->directives->args). I am new to the GraphQL spec, so I need to dig in more.

Could #3048 be related as well?

1reaction
MichalLytekcommented, Feb 28, 2021

@IvanGoncharov I can confirm this bug on v15.5.0, as soon when I enable inputValueDeprecation: true in getIntrospectionQuery.

GraphQLError: Unknown argument “includeDeprecated” on field “__Directive.args”.

Looks like that function generates that (includeDeprecated: true) on a wrong node.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Graphql Unknown argument on field - Stack Overflow
Whenever I try to send args on (posts) child node like the query below, I get an error msg "Unknown argument id on...
Read more >
Directives - GraphQL .NET
A directive can be attached to almost every part of the schema - field, query, ... InlineFragment) { Description = "My super directive";...
Read more >
GraphQL specification
GraphQL Documents are full of named things: operations, fields, arguments, types, directives, fragments, and variables. All names must follow the same ...
Read more >
Directives - Apollo GraphQL Docs
Configure GraphQL types, fields, and arguments. ... A directive decorates part of a GraphQL schema or operation with additional configuration.
Read more >
graphql - Awesome JS
#3645 createSourceEventStream: introduce named arguments and deprecate positional ... add missing __Directive.args(includeDeprecated:) (@IvanGoncharov) ...
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