diff --git a/fixtures/directiveSchemas/baseTypes.graphql b/fixtures/directiveSchemas/baseTypes.graphql index 3ef5274..8f7d59b 100644 --- a/fixtures/directiveSchemas/baseTypes.graphql +++ b/fixtures/directiveSchemas/baseTypes.graphql @@ -27,4 +27,5 @@ enum Bar { input Input { field: String @nullArg(stringArg: "string") oldAttribute: String! @deprecated(reason: "reason") -} \ No newline at end of file + fieldWithEscapeString: String @escapedStringArg(escapedString: "\b,\f,\n,\r,\t,...,\\,{,}") +} diff --git a/fixtures/directiveSchemas/directives.graphql b/fixtures/directiveSchemas/directives.graphql index f1cc6c9..49f66a4 100644 --- a/fixtures/directiveSchemas/directives.graphql +++ b/fixtures/directiveSchemas/directives.graphql @@ -10,3 +10,6 @@ directive @nullArg(stringArg: String) on ENUM_VALUE | FIELD_DEFINITION | INPUT_F """The directives decorates unions.""" directive @nestedFooUnion on UNION union NestedFooUnion @nestedFooUnion = NestedFoo + +"""The directive accepts escaped string.""" +directive @escapedStringArg(escapedString: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION diff --git a/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql b/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql index aa18f8d..159a373 100644 --- a/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql +++ b/fixtures/expectedOutput/directiveSchemas/printedDefault.graphql @@ -9,6 +9,9 @@ directive @nullArg(stringArg: String) on ENUM_VALUE | FIELD_DEFINITION | INPUT_F """The directives decorates unions.""" directive @nestedFooUnion on UNION +"""The directive accepts escaped string.""" +directive @escapedStringArg(escapedString: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION + interface BarInterface { bar: String! } @@ -40,6 +43,7 @@ enum Bar { input Input { field: String oldAttribute: String! @deprecated(reason: "reason") + fieldWithEscapeString: String } union NestedFooUnion = NestedFoo diff --git a/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql b/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql index 487c2b6..9d2036b 100644 --- a/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql +++ b/fixtures/expectedOutput/directiveSchemas/printedWithDirectives.graphql @@ -9,6 +9,9 @@ directive @nullArg(stringArg: String) on ENUM_VALUE | FIELD_DEFINITION | INPUT_F """The directives decorates unions.""" directive @nestedFooUnion on UNION +"""The directive accepts escaped string.""" +directive @escapedStringArg(escapedString: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION + enum Bar { MORE @multiArgAndType(stringArg: "string", booleanArg: true, intArg: 314, floatArg: 3.14, listArg: ["string"], enumArg: VALUES) VALUES @@ -33,6 +36,7 @@ interface FooInterface implements BarInterface { input Input { field: String @nullArg(stringArg: "string") oldAttribute: String! @deprecated(reason: "reason") + fieldWithEscapeString: String @escapedStringArg(escapedString: "\b,\f,\n,\r,\t,...,\\,{,}") } type NestedFoo { diff --git a/src/printers.ts b/src/printers.ts index 1c40148..8f18301 100644 --- a/src/printers.ts +++ b/src/printers.ts @@ -380,7 +380,7 @@ function printLiteralArgumentValueNode(node: IntValueNode | FloatValueNode | Boo } function printStringValueNode(node: StringValueNode) { - return '"' + node.value + '"'; + return JSON.stringify(node.value); } function printNullValueNode(node: NullValueNode) {