Skip to content

Commit

Permalink
Merge branch 'master' into passContextToLocalDataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
James Baxley committed Jun 12, 2019
2 parents 01baddf + ead50a0 commit df28c0b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 27 deletions.
2 changes: 2 additions & 0 deletions federation-js/CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

### vNEXT

* Allow specified directives during validation (@deprecated) [#2823](https://github.com/apollographql/apollo-server/pull/2823)

# v0.6.1

* Normalize SDL in a normalization step before validation [#2771](https://github.com/apollographql/apollo-server/pull/2771)
2 changes: 1 addition & 1 deletion federation-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@apollo/federation",
"version": "0.6.2",
"version": "0.6.3",
"description": "Apollo Federation Utilities",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Expand Up @@ -51,6 +51,37 @@ describe('keyFieldsMissingExternal', () => {
expect(warnings).toHaveLength(0);
});

it('has no warnings with @deprecated directive usage', () => {
const serviceA = {
typeDefs: gql`
extend type Car @key(fields: "model { name kit { upc } } year") {
model: Model! @external
year: String! @external
color: String! @deprecated(reason: "Use colors instead")
colors: Color!
}
extend type Model {
name: String! @external
kit: Kit @external
}
extend type Kit {
upc: String! @external
}
enum Color {
Red
Blue
}
`,
name: 'serviceA',
};

const warnings = validateKeyFieldsMissingExternal(serviceA);
expect(warnings).toHaveLength(0);
});

it("warns when a @key argument doesn't reference an @external field", () => {
const serviceA = {
typeDefs: gql`
Expand Down
Expand Up @@ -5,6 +5,7 @@ import {
parse,
GraphQLSchema,
GraphQLError,
specifiedDirectives,
} from 'graphql';
import { buildSchemaFromSDL } from 'apollo-graphql';
import { isNotNullOrUndefined } from 'apollo-env';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const keyFieldsMissingExternal = ({
// this allows us to build a partial schema
let schema = new GraphQLSchema({
query: undefined,
directives: federationDirectives,
directives: [...specifiedDirectives, ...federationDirectives],
});
try {
schema = buildSchemaFromSDL(typeDefs, schema);
Expand Down
55 changes: 55 additions & 0 deletions federation-js/src/service/__tests__/buildFederatedSchema.test.ts
Expand Up @@ -73,6 +73,61 @@ type Money {
`);
});

it('should preserve description text in generated SDL', async () => {
const query = `query GetServiceDetails {
_service {
sdl
}
}`;
const schema = buildFederatedSchema(gql`
"A user. This user is very complicated and requires so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so much description text"
type User @key(fields: "id") {
"""
The unique ID of the user.
"""
id: ID!
"The user's name."
name: String
username: String
foo(
"Description 1"
arg1: String
"Description 2"
arg2: String
"Description 3 Description 3 Description 3 Description 3 Description 3 Description 3 Description 3 Description 3 Description 3 Description 3 Description 3"
arg3: String
): String
}
`);

const { data, errors } = await graphql(schema, query);
expect(errors).toBeUndefined();
expect(data._service.sdl).toEqual(`"""
A user. This user is very complicated and requires so so so so so so so so so so
so so so so so so so so so so so so so so so so so so so so so so much
description text
"""
type User @key(fields: "id") {
"The unique ID of the user."
id: ID!
"The user's name."
name: String
username: String
foo(
"Description 1"
arg1: String
"Description 2"
arg2: String
"""
Description 3 Description 3 Description 3 Description 3 Description 3
Description 3 Description 3 Description 3 Description 3 Description 3 Description 3
"""
arg3: String
): String
}
`);
});

describe(`should add an _entities query root field to the schema`, () => {
it(`when a query root type with the default name has been defined`, () => {
const schema = buildFederatedSchema(gql`
Expand Down
37 changes: 13 additions & 24 deletions federation-js/src/service/printFederatedSchema.ts
Expand Up @@ -220,8 +220,8 @@ function printEnum(type: GraphQLEnumType): string {
const values = type
.getValues()
.map(
(value, i) =>
printDescription(value, ' ', !i) +
value =>
printDescription(value, ' ') +
' ' +
value.name +
printDeprecated(value),
Expand All @@ -232,7 +232,7 @@ function printEnum(type: GraphQLEnumType): string {

function printInputObject(type: GraphQLInputObjectType): string {
const fields = Object.values(type.getFields()).map(
(f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f),
f => printDescription(f, ' ') + ' ' + printInputValue(f),
);
return printDescription(type) + `input ${type.name}` + printBlock(fields);
}
Expand All @@ -241,8 +241,8 @@ function printFields(
type: GraphQLInterfaceType | GraphQLObjectType | GraphQLInputObjectType,
) {
const fields = Object.values(type.getFields()).map(
(f, i) =>
printDescription(f, ' ', !i) +
f =>
printDescription(f, ' ') +
' ' +
f.name +
printArgs(f.args, ' ') +
Expand Down Expand Up @@ -272,8 +272,8 @@ function printArgs(args: GraphQLArgument[], indentation = '') {
'(\n' +
args
.map(
(arg, i) =>
printDescription(arg, ' ' + indentation, !i) +
arg =>
printDescription(arg, ' ' + indentation) +
' ' +
indentation +
printInputValue(arg),
Expand Down Expand Up @@ -332,30 +332,19 @@ function printDescription(
| GraphQLEnumValue
| GraphQLUnionType,
indentation: string = '',
firstInBlock: boolean = true,
): string {
if (!def.description) {
return '';
}

const lines = descriptionLines(def.description, 120 - indentation.length);
return printDescriptionWithComments(lines, indentation, firstInBlock);
}

function printDescriptionWithComments(
lines: string[],
indentation: string,
firstInBlock: boolean,
) {
let description = indentation && !firstInBlock ? '\n' : '';
for (let i = 0; i < lines.length; i++) {
if (lines[i] === '') {
description += indentation + '#\n';
} else {
description += indentation + '# ' + lines[i] + '\n';
}
if (lines.length === 1) {
return indentation + `"${lines[0]}"\n`;
} else {
return (
indentation + ['"""', ...lines, '"""'].join('\n' + indentation) + '\n'
);
}
return description;
}

function descriptionLines(description: string, maxLen: number): Array<string> {
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@apollo/gateway",
"version": "0.6.5",
"version": "0.6.6",
"description": "Apollo Gateway",
"author": "opensource@apollographql.com",
"main": "dist/index.js",
Expand Down

0 comments on commit df28c0b

Please sign in to comment.