Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print: add spaces inside input object #3456

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/language/__tests__/printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe('Printer: Query document', () => {

it('prints query with variable directives', () => {
const queryASTWithVariableDirective = parse(
'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
'query ($foo: TestType = { a: 123 } @testDirective(if: true) @test) { id }',
);
expect(print(queryASTWithVariableDirective)).to.equal(dedent`
query ($foo: TestType = {a: 123} @testDirective(if: true) @test) {
query ($foo: TestType = { a: 123 } @testDirective(if: true) @test) {
id
}
`);
Expand Down Expand Up @@ -196,9 +196,9 @@ describe('Printer: Query document', () => {
foo(
size: $size
bar: $b
obj: {key: "value", block: """
obj: { key: "value", block: """
block string uses \"""
"""}
""" }
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/schema-printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Printer: SDL document', () => {
three(argument: InputType, other: String): Int
four(argument: String = "string"): String
five(argument: [String] = ["string", "string"]): String
six(argument: InputType = {key: "value"}): Type
six(argument: InputType = { key: "value" }): Type
seven(argument: Int = null): Type
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const printDocASTReducer: ASTReducer<string> = {
NullValue: { leave: () => 'null' },
EnumValue: { leave: ({ value }) => value },
ListValue: { leave: ({ values }) => '[' + join(values, ', ') + ']' },
ObjectValue: { leave: ({ fields }) => '{' + join(fields, ', ') + '}' },
ObjectValue: { leave: ({ fields }) => '{ ' + join(fields, ', ') + ' }' },
ObjectField: { leave: ({ name, value }) => name + ': ' + value },

// Directive
Expand Down
4 changes: 2 additions & 2 deletions src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ describe('Introspection', () => {
const schema = buildSchema(`
input InputObjectWithDefaultValues {
a: String = "Emoji: \\u{1F600}"
b: Complex = {x: ["abc"], y: 123}
b: Complex = { x: ["abc"], y: 123 }
}

input Complex {
Expand Down Expand Up @@ -1120,7 +1120,7 @@ describe('Introspection', () => {
},
{
name: 'b',
defaultValue: '{x: ["abc"], y: 123}',
defaultValue: '{ x: ["abc"], y: 123 }',
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions src/type/__tests__/scalars-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Type System: Specified scalar types', () => {
'Int cannot represent non-integer value: [1]',
);
expect(() => parseLiteral('{ value: 1 }')).to.throw(
'Int cannot represent non-integer value: {value: 1}',
'Int cannot represent non-integer value: { value: 1 }',
);
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
'Int cannot represent non-integer value: ENUM_VALUE',
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('Type System: Specified scalar types', () => {
'Float cannot represent non numeric value: [0.1]',
);
expect(() => parseLiteral('{ value: 0.1 }')).to.throw(
'Float cannot represent non numeric value: {value: 0.1}',
'Float cannot represent non numeric value: { value: 0.1 }',
);
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
'Float cannot represent non numeric value: ENUM_VALUE',
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('Type System: Specified scalar types', () => {
'String cannot represent a non string value: ["foo"]',
);
expect(() => parseLiteral('{ value: "foo" }')).to.throw(
'String cannot represent a non string value: {value: "foo"}',
'String cannot represent a non string value: { value: "foo" }',
);
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
'String cannot represent a non string value: ENUM_VALUE',
Expand Down Expand Up @@ -484,7 +484,7 @@ describe('Type System: Specified scalar types', () => {
'Boolean cannot represent a non boolean value: [false]',
);
expect(() => parseLiteral('{ value: false }')).to.throw(
'Boolean cannot represent a non boolean value: {value: false}',
'Boolean cannot represent a non boolean value: { value: false }',
);
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
'Boolean cannot represent a non boolean value: ENUM_VALUE',
Expand Down Expand Up @@ -599,7 +599,7 @@ describe('Type System: Specified scalar types', () => {
'ID cannot represent a non-string and non-integer value: ["1"]',
);
expect(() => parseLiteral('{ value: "1" }')).to.throw(
'ID cannot represent a non-string and non-integer value: {value: "1"}',
'ID cannot represent a non-string and non-integer value: { value: "1" }',
);
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
'ID cannot represent a non-string and non-integer value: ENUM_VALUE',
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__tests__/buildClientSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ describe('Type System: build schema from introspection', () => {
type Query {
defaultInt(intArg: Int = 30): String
defaultList(listArg: [Int] = [1, 2, 3]): String
defaultObject(objArg: Geo = {lat: 37.485, lon: -122.148}): String
defaultObject(objArg: Geo = { lat: 37.485, lon: -122.148 }): String
defaultNull(intArg: Int = null): String
noDefault(intArg: Int): String
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__tests__/findBreakingChanges-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ describe('findDangerousChanges', () => {
{
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
description:
'Type1.field1 arg complexObject has changed defaultValue from {innerInputArray: [{arrayField: [1, 2, 3]}]} to {innerInputArray: [{arrayField: [3, 2, 1]}]}.',
'Type1.field1 arg complexObject has changed defaultValue from { innerInputArray: [{ arrayField: [1, 2, 3] }] } to { innerInputArray: [{ arrayField: [3, 2, 1] }] }.',
},
]);
});
Expand Down
12 changes: 7 additions & 5 deletions src/utilities/__tests__/sortValueNode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('sortValueNode', () => {
});

it('sort input object fields', () => {
expectSortedValue('{ b: 2, a: 1 }').to.equal('{a: 1, b: 2}');
expectSortedValue('{ a: { c: 3, b: 2 } }').to.equal('{a: {b: 2, c: 3}}');
expectSortedValue('[{ b: 2, a: 1 }, { d: 4, c: 3}]').to.equal(
'[{a: 1, b: 2}, {c: 3, d: 4}]',
expectSortedValue('{ b: 2, a: 1 }').to.equal('{ a: 1, b: 2 }');
expectSortedValue('{ a: { c: 3, b: 2 } }').to.equal(
'{ a: { b: 2, c: 3 } }',
);
expectSortedValue('[{ b: 2, a: 1 }, { d: 4, c: 3 }]').to.equal(
'[{ a: 1, b: 2 }, { c: 3, d: 4 }]',
);
expectSortedValue(
'{ b: { g: 7, f: 6 }, c: 3 , a: { d: 4, e: 5 } }',
).to.equal('{a: {d: 4, e: 5}, b: {f: 6, g: 7}, c: 3}');
).to.equal('{ a: { d: 4, e: 5 }, b: { f: 6, g: 7 }, c: 3 }');
});
});