Skip to content

Regression v16: typeInfo.getFieldDef() missing description 🐛 #3606

Closed
@simlu

Description

@simlu

In version 16.x we are no longer getting the description returned as expected. I've put together a small test case.

This works fine with 15.x

import assert from 'assert';
import {
  parse, TypeInfo, validate, visit, visitWithTypeInfo
} from 'graphql';
import { makeExecutableSchema } from '@graphql-tools/schema';

// schemas as defined by server
const schema = makeExecutableSchema({
  typeDefs: [
    'type Notification {',
    '  # some description',
    '  id: ID',
    '}',
    'type Query { Notification: Notification }'
  ].join('\n'),
  parseOptions: {
    commentDescriptions: true
  }
});
// ast as defined by query
const ast = parse('query Notification { Notification { id } }');

// making sure everything is fine
const errors = validate(schema, ast);
assert(errors.length === 0);

// the actually changed behavior below
const typeInfo = new TypeInfo(schema);
visit(ast, visitWithTypeInfo(typeInfo, {
  enter(node, key, parent, path, ancestors) {
    const fieldDef = typeInfo.getFieldDef();
    if (fieldDef?.name === 'id') {
      console.log([key, fieldDef?.description]);
    }
  }
}));
// => [ 0, 'some description' ]
// => [ 'name', 'some description' ]

but with 16.x we are getting back

// => [ 0, undefined ]
// => [ 'name', undefined ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions