Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
s/fieldName/memberName

Adds wrapping object around return type of resolveSchemaCoordinate to ensure it's easy to use that result.
  • Loading branch information
leebyron committed Apr 22, 2021
1 parent b2cf85c commit 42f9072
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export {
GraphQLScalarSerializer,
GraphQLScalarValueParser,
GraphQLScalarLiteralParser,
GraphQLSchemaElement,
} from './type/index';

// Parse and operate on GraphQL language source files.
Expand Down Expand Up @@ -462,4 +461,5 @@ export {
BreakingChange,
DangerousChange,
TypedQueryDocumentNode,
GraphQLSchemaElement,
} from './utilities/index';
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export type {
GraphQLScalarSerializer,
GraphQLScalarValueParser,
GraphQLScalarLiteralParser,
GraphQLSchemaElement,
} from './type/index';

// Parse and operate on GraphQL language source files.
Expand Down Expand Up @@ -450,4 +449,5 @@ export type {
BuildSchemaOptions,
BreakingChange,
DangerousChange,
GraphQLSchemaElement,
} from './utilities/index';
10 changes: 5 additions & 5 deletions src/language/__tests__/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('Parser', () => {
loc: { start: 0, end: 6 },
value: 'MyType',
},
fieldName: undefined,
memberName: undefined,
argumentName: undefined,
});
});
Expand All @@ -560,7 +560,7 @@ describe('Parser', () => {
loc: { start: 0, end: 6 },
value: 'MyType',
},
fieldName: {
memberName: {
kind: Kind.NAME,
loc: { start: 7, end: 12 },
value: 'field',
Expand Down Expand Up @@ -589,7 +589,7 @@ describe('Parser', () => {
loc: { start: 0, end: 6 },
value: 'MyType',
},
fieldName: {
memberName: {
kind: Kind.NAME,
loc: { start: 7, end: 12 },
value: 'field',
Expand Down Expand Up @@ -622,7 +622,7 @@ describe('Parser', () => {
loc: { start: 1, end: 12 },
value: 'myDirective',
},
fieldName: undefined,
memberName: undefined,
argumentName: undefined,
});
});
Expand All @@ -638,7 +638,7 @@ describe('Parser', () => {
loc: { start: 1, end: 12 },
value: 'myDirective',
},
fieldName: undefined,
memberName: undefined,
argumentName: {
kind: Kind.NAME,
loc: { start: 13, end: 16 },
Expand Down
2 changes: 1 addition & 1 deletion src/language/ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,6 @@ export interface SchemaCoordinateNode {
readonly loc?: Location;
readonly isDirective: boolean;
readonly name: NameNode;
readonly fieldName?: NameNode;
readonly memberName?: NameNode;
readonly argumentName?: NameNode;
}
2 changes: 1 addition & 1 deletion src/language/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,6 @@ export type SchemaCoordinateNode = {|
+loc?: Location,
+isDirective: boolean,
+name: NameNode,
+fieldName?: NameNode,
+memberName?: NameNode,
+argumentName?: NameNode,
|};
8 changes: 4 additions & 4 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,13 +1371,13 @@ export class Parser {
const start = this._lexer.token;
const isDirective = this.expectOptionalToken(TokenKind.AT);
const name = this.parseName();
let fieldName;
let memberName;
if (!isDirective && this.expectOptionalToken(TokenKind.DOT)) {
fieldName = this.parseName();
memberName = this.parseName();
}
let argumentName;
if (
(isDirective || fieldName) &&
(isDirective || memberName) &&
this.expectOptionalToken(TokenKind.PAREN_L)
) {
argumentName = this.parseName();
Expand All @@ -1388,7 +1388,7 @@ export class Parser {
kind: Kind.SCHEMA_COORDINATE,
isDirective,
name,
fieldName,
memberName,
argumentName,
loc: this.loc(start),
};
Expand Down
4 changes: 2 additions & 2 deletions src/language/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ const printDocASTReducer: any = {
// Schema Coordinate

SchemaCoordinate: {
leave: ({ isDirective, name, fieldName, argumentName }) =>
leave: ({ isDirective, name, memberName, argumentName }) =>
join([
isDirective && '@',
name,
wrap('.', fieldName),
wrap('.', memberName),
wrap('(', argumentName, ':)'),
]),
},
Expand Down
2 changes: 1 addition & 1 deletion src/language/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const QueryDocumentKeys = {
EnumTypeExtension: ['name', 'directives', 'values'],
InputObjectTypeExtension: ['name', 'directives', 'fields'],

SchemaCoordinate: ['name', 'fieldName', 'argumentName'],
SchemaCoordinate: ['name', 'memberName', 'argumentName'],
};

export const BREAK: { ... } = Object.freeze({});
Expand Down
16 changes: 0 additions & 16 deletions src/type/element.d.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/type/element.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/type/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,3 @@ export {
} from './introspection';

export { validateSchema, assertValidSchema } from './validate';

// Schema Element type.
export { GraphQLSchemaElement } from './element';
3 changes: 0 additions & 3 deletions src/type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,3 @@ export type {

// Validate GraphQL schema.
export { validateSchema, assertValidSchema } from './validate';

// Schema Element type.
export type { GraphQLSchemaElement } from './element';
157 changes: 94 additions & 63 deletions src/utilities/__tests__/resolveSchemaCoordinate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,116 +31,147 @@ describe('resolveSchemaCoordinate', () => {
`);

it('resolves a Named Type', () => {
const expected = schema.getType('Business');
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'Business')).to.equal(expected);
expect(resolveSchemaCoordinate(schema, 'Business')).to.deep.equal({
kind: 'NamedType',
type: schema.getType('Business'),
});

expect(resolveSchemaCoordinate(schema, 'String')).to.equal(
schema.getType('String'),
);
expect(resolveSchemaCoordinate(schema, 'String')).to.deep.equal({
kind: 'NamedType',
type: schema.getType('String'),
});

expect(resolveSchemaCoordinate(schema, 'private')).to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'private')).to.deep.equal(undefined);

expect(resolveSchemaCoordinate(schema, 'Unknown')).to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'Unknown')).to.deep.equal(undefined);
});

it('resolves a Type Field', () => {
const expected = schema.getType('Business').getFields().name;
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'Business.name')).to.equal(expected);

expect(resolveSchemaCoordinate(schema, 'Business.unknown')).to.equal(
const type = schema.getType('Business');
const field = type.getFields().name;
expect(resolveSchemaCoordinate(schema, 'Business.name')).to.deep.equal({
kind: 'Field',
type,
field,
});

expect(resolveSchemaCoordinate(schema, 'Business.unknown')).to.deep.equal(
undefined,
);

expect(resolveSchemaCoordinate(schema, 'Unknown.field')).to.equal(
expect(resolveSchemaCoordinate(schema, 'Unknown.field')).to.deep.equal(
undefined,
);

expect(resolveSchemaCoordinate(schema, 'String.field')).to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'String.field')).to.deep.equal(
undefined,
);
});

it('does not resolve meta-fields', () => {
expect(resolveSchemaCoordinate(schema, 'Business.__typename')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'Business.__typename'),
).to.deep.equal(undefined);
});

it('resolves a Input Field', () => {
const expected = schema.getType('SearchCriteria').getFields().filter;
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'SearchCriteria.filter')).to.equal(
expected,
);
const type = schema.getType('SearchCriteria');
const inputField = type.getFields().filter;
expect(
resolveSchemaCoordinate(schema, 'SearchCriteria.filter'),
).to.deep.equal({
kind: 'InputField',
type,
inputField,
});

expect(resolveSchemaCoordinate(schema, 'SearchCriteria.unknown')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'SearchCriteria.unknown'),
).to.deep.equal(undefined);
});

it('resolves a Enum Value', () => {
const expected = schema.getType('SearchFilter').getValue('OPEN_NOW');
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, 'SearchFilter.OPEN_NOW')).to.equal(
expected,
);
const type = schema.getType('SearchFilter');
const enumValue = type.getValue('OPEN_NOW');
expect(
resolveSchemaCoordinate(schema, 'SearchFilter.OPEN_NOW'),
).to.deep.equal({
kind: 'EnumValue',
type,
enumValue,
});

expect(resolveSchemaCoordinate(schema, 'SearchFilter.UNKNOWN')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'SearchFilter.UNKNOWN'),
).to.deep.equal(undefined);
});

it('resolves a Field Argument', () => {
const expected = schema
.getType('Query')
.getFields()
.searchBusiness.args.find((arg) => arg.name === 'criteria');
expect(expected).not.to.equal(undefined);
const type = schema.getType('Query');
const field = type.getFields().searchBusiness;
const fieldArgument = field.args.find((arg) => arg.name === 'criteria');
expect(
resolveSchemaCoordinate(schema, 'Query.searchBusiness(criteria:)'),
).to.equal(expected);
).to.deep.equal({
kind: 'FieldArgument',
type,
field,
fieldArgument,
});

expect(resolveSchemaCoordinate(schema, 'Business.name(unknown:)')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'Business.name(unknown:)'),
).to.deep.equal(undefined);

expect(resolveSchemaCoordinate(schema, 'Unknown.field(arg:)')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'Unknown.field(arg:)'),
).to.deep.equal(undefined);

expect(resolveSchemaCoordinate(schema, 'Business.unknown(arg:)')).to.equal(
undefined,
);
expect(
resolveSchemaCoordinate(schema, 'Business.unknown(arg:)'),
).to.deep.equal(undefined);

expect(
resolveSchemaCoordinate(schema, 'SearchCriteria.name(arg:)'),
).to.equal(undefined);
).to.deep.equal(undefined);
});

it('resolves a Directive', () => {
const expected = schema.getDirective('private');
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, '@private')).to.equal(expected);
expect(resolveSchemaCoordinate(schema, '@private')).to.deep.equal({
kind: 'Directive',
directive: schema.getDirective('private'),
});

expect(resolveSchemaCoordinate(schema, '@unknown')).to.equal(undefined);
expect(resolveSchemaCoordinate(schema, '@deprecated')).to.deep.equal({
kind: 'Directive',
directive: schema.getDirective('deprecated'),
});

expect(resolveSchemaCoordinate(schema, '@Business')).to.equal(undefined);
expect(resolveSchemaCoordinate(schema, '@unknown')).to.deep.equal(
undefined,
);

expect(resolveSchemaCoordinate(schema, '@Business')).to.deep.equal(
undefined,
);
});

it('resolves a Directive Argument', () => {
const expected = schema
.getDirective('private')
.args.find((arg) => arg.name === 'scope');
expect(expected).not.to.equal(undefined);
expect(resolveSchemaCoordinate(schema, '@private(scope:)')).to.equal(
expected,
const directive = schema.getDirective('private');
const directiveArgument = directive.args.find(
(arg) => arg.name === 'scope',
);
expect(resolveSchemaCoordinate(schema, '@private(scope:)')).to.deep.equal({
kind: 'DirectiveArgument',
directive,
directiveArgument,
});

expect(resolveSchemaCoordinate(schema, '@private(unknown:)')).to.equal(
expect(resolveSchemaCoordinate(schema, '@private(unknown:)')).to.deep.equal(
undefined,
);

expect(resolveSchemaCoordinate(schema, '@unknown(arg:)')).to.equal(
expect(resolveSchemaCoordinate(schema, '@unknown(arg:)')).to.deep.equal(
undefined,
);
});
Expand Down
Loading

0 comments on commit 42f9072

Please sign in to comment.