-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support backtick strings as constants
- Loading branch information
1 parent
bc5527c
commit 6233439
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/tests/fixtures/default_values/DefaultArgumentStringLiteralBackticks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @gqlType */ | ||
export default class SomeType { | ||
/** @gqlField */ | ||
hello({ greeting = `hello` }: { greeting: string }): string { | ||
return `${greeting} world!`; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/tests/fixtures/default_values/DefaultArgumentStringLiteralBackticks.ts.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
/** @gqlType */ | ||
export default class SomeType { | ||
/** @gqlField */ | ||
hello({ greeting = `hello` }: { greeting: string }): string { | ||
return `${greeting} world!`; | ||
} | ||
} | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
hello(greeting: String! = "hello"): String @metadata | ||
} | ||
-- TypeScript -- | ||
import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql"; | ||
export function getSchema(): GraphQLSchema { | ||
const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({ | ||
name: "SomeType", | ||
fields() { | ||
return { | ||
hello: { | ||
name: "hello", | ||
type: GraphQLString, | ||
args: { | ||
greeting: { | ||
name: "greeting", | ||
type: new GraphQLNonNull(GraphQLString), | ||
defaultValue: "hello" | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
return new GraphQLSchema({ | ||
types: [SomeTypeType] | ||
}); | ||
} |
9 changes: 9 additions & 0 deletions
9
...ests/fixtures/default_values/DefaultArgumentStringLiteralBackticksInterpolated.invalid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const CONSTANT = "constant"; | ||
|
||
/** @gqlType */ | ||
export default class SomeType { | ||
/** @gqlField */ | ||
hello({ greeting = `hello ${CONSTANT}` }: { greeting: string }): string { | ||
return `${greeting} world!`; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ures/default_values/DefaultArgumentStringLiteralBackticksInterpolated.invalid.ts.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
----------------- | ||
INPUT | ||
----------------- | ||
const CONSTANT = "constant"; | ||
|
||
/** @gqlType */ | ||
export default class SomeType { | ||
/** @gqlField */ | ||
hello({ greeting = `hello ${CONSTANT}` }: { greeting: string }): string { | ||
return `${greeting} world!`; | ||
} | ||
} | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
src/tests/fixtures/default_values/DefaultArgumentStringLiteralBackticksInterpolated.invalid.ts:6:22 - error: Expected GraphQL field argument default values to be a literal. Grats interprets argument defaults as GraphQL default values, which must be literals. For example: `10` or `"foo"`. | ||
|
||
If you think Grats should be able to infer this constant value, please report an issue at https://github.com/captbaritone/grats/issues. | ||
|
||
6 hello({ greeting = `hello ${CONSTANT}` }: { greeting: string }): string { | ||
~~~~~~~~~~~~~~~~~~~ |