-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow an arg to be optional and not nullable if a default is provided
- Loading branch information
1 parent
a5bc9f2
commit ab43016
Showing
4 changed files
with
92 additions
and
10 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/arguments/OptionalNonNullableArgumentWithDefault.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 ?? "Hello"} World!`; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/tests/fixtures/arguments/OptionalNonNullableArgumentWithDefault.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 ?? "Hello"} World!`; | ||
} | ||
} | ||
|
||
----------------- | ||
OUTPUT | ||
----------------- | ||
-- SDL -- | ||
type SomeType { | ||
hello(greeting: String! = "Hello"): String @metadata(argCount: 1) | ||
} | ||
-- 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] | ||
}); | ||
} |
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