Skip to content

Commit 693c3ab

Browse files
Yoon LeeErikWittern
authored andcommitted
Add option for generic payload argument name, 'requestBody', for mutations
Signed-off-by: Yoon Lee <[email protected]>
1 parent bb460b3 commit 693c3ab

17 files changed

+150
-43
lines changed

packages/openapi-to-graphql-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Options:
3333
-o, --operationIdFieldNames create field names based on the operationId
3434
-f, --fillEmptyResponses create placeholder schemas for operations with no response body rather than ignore them
3535
-a, --addLimitArgument add a limit argument on fields returning lists of objects/lists to control the data size
36+
-g, --genericPayloadArgName Sets argument name for the payload of a mutation to 'requestBody'
3637
3738
-H, --header <key:value> add headers to every request; repeatable flag; set using key:value notation (default: [])
3839
-Q, --queryString <key:value> add query parameters to every request; repeatable flag; set using key:value notation (default: [])

packages/openapi-to-graphql-cli/src/openapi-to-graphql.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ program
5050
'-a, --addLimitArgument',
5151
'add a limit argument on fields returning lists of objects/lists to control the data size'
5252
)
53+
.option(
54+
'-g, --genericPayloadArgName',
55+
'Sets argument name for the payload of a mutation to \'requestBody\''
56+
)
5357

5458
// Resolver options
5559
.option(
@@ -102,6 +106,7 @@ const options: Options = {
102106
operationIdFieldNames: program.operationIdFieldNames,
103107
fillEmptyResponses: program.fillEmptyResponses,
104108
addLimitArgument: program.addLimitArgument,
109+
genericPayloadArgName: program.genericPayloadArgName,
105110

106111
// Resolver options
107112
headers,

packages/openapi-to-graphql/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Schema options:
158158

159159
- `selectQueryOrMutationField` (type: `object`, default: `{}`): OpenAPI-to-GraphQL, by default, will make all GET operations into `Query` fields and all other operations into `Mutation` fields. This option allows users to manually override this process. The operation is identifed first by the [title](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#infoObject) of the OAS, then the [path](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#paths-object) of the operation, and lastly the [method](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#path-item-object) of the operation. The `selectQueryOrMutationField` object is thus a triply nested object where the outer key is the title, followed by the path, and finally the method, which points to an integer value of either `0`, or `1`, corresponding to `Query` or `Mutation` type respectively.
160160

161+
- `genericPayloadArgName` (type: `boolean`, default: `false`): Set the default argument name for the payload of a mutation to `requestBody`. Otherwise, the name will default to the camelCased pathname.
162+
161163
***
162164

163165
Resolver options:

packages/openapi-to-graphql/lib/index.js

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/resolver_builder.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/resolver_builder.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/schema_builder.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare type GetGraphQLTypeParams = {
1313
isInputObjectType?: boolean;
1414
};
1515
declare type GetArgsParams = {
16-
def?: DataDefinition;
16+
requestPayloadDef?: DataDefinition;
1717
parameters: ParameterObject[];
1818
operation?: Operation;
1919
data: PreprocessingData;
@@ -23,8 +23,7 @@ declare type GetArgsParams = {
2323
*/
2424
export declare function getGraphQLType({ def, operation, data, iteration, isInputObjectType }: GetGraphQLTypeParams): GraphQLType;
2525
/**
26-
* Creates an object with the arguments for resolving a GraphQL (Input) Object
27-
* Type
26+
* Creates the arguments for resolving a field
2827
*/
29-
export declare function getArgs({ def, parameters, operation, data }: GetArgsParams): Args;
28+
export declare function getArgs({ requestPayloadDef, parameters, operation, data }: GetArgsParams): Args;
3029
export {};

packages/openapi-to-graphql/lib/schema_builder.js

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/schema_builder.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)