Skip to content

Commit ced79cd

Browse files
Alan-ChaErikWittern
authored andcommitted
Add addLimitArgument option
Updated license to confirm with MIT template Signed-off-by: Alan Cha <[email protected]>
1 parent 25147d0 commit ced79cd

24 files changed

+1894
-1316
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Options:
2727
-u, --url <url> select the base url which paths will be built on
2828
-s, --strict throw an error if OpenAPI-to-GraphQL cannot run without compensating for errors or missing data in the OAS
2929
-f, --fillEmptyResponses create placeholder schemas for operations with HTTP status code 204 (no response) rather than ignore them
30+
-a, --addLimitArgument add a limit argument on fields returning lists of objects/lists that will constrain the list size
3031
-o, --operationIdFieldNames create field names based on the operationId
3132
--cors enable Cross-origin resource sharing (CORS)
3233
--no-viewer do not create GraphQL viewer objects for passing authentication credentials

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

Lines changed: 3 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-cli/lib/openapi-to-graphql.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-cli/src/openapi-to-graphql.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ program
3232
'-f, --fillEmptyResponses',
3333
'create placeholder schemas for operations with HTTP status code 204 (no response) rather than ignore them'
3434
)
35+
.option(
36+
'-a, --addLimitArgument',
37+
'add limit argument on fields returning lists of objects/lists to control the data size'
38+
)
3539
.option(
3640
'-o, --operationIdFieldNames',
3741
'create field names based on the operationId'
@@ -157,7 +161,8 @@ function startGraphQLServer(oas, port) {
157161
fillEmptyResponses: program.fillEmptyResponses,
158162
baseUrl: program.url,
159163
operationIdFieldNames: program.operationIdFieldNames,
160-
provideErrorExtensions: program.extensions
164+
provideErrorExtensions: program.extensions,
165+
addLimitArgument: program.addLimitArgument
161166
})
162167
.then(({ schema, report }) => {
163168
console.log(JSON.stringify(report, null, 2))

packages/openapi-to-graphql/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ The options object can contain the following properties:
164164

165165
- `customResolvers` (type: `object`, default: `{}`): OpenAPI-to-GraphQL, per default, creates resolver functions that make REST calls to resolve fields in the generated GraphQL interface. This option allows users to provide custom resolver functions to be used in place of said ones created by OpenAPI-to-GraphQL. The field that the custom resolver will affect 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 `customResolvers` 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 the [resolver function](https://graphql.org/learn/execution/#root-fields-resolvers) itself. The resolver function can use the parameters `obj`, `args`, `context`, and `info` in order to produce the proper data, as do standard [resolver functions](https://graphql.org/learn/execution/#root-fields-resolvers) in GraphQL. Use cases include the resolution of complex relationships between types, implementing performance improvements like caching, or dealing with non-standard authentication requirements. _Note: Because the arguments are provided by the GraphQL interface, they may look different from the [parameters](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject) defined by the OAS. For example, they will have [sanitized](https://github.com/Alan-Cha/openapi-to-graphql#characteristics) names. The [request body](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#requestBodyObject) will also be contained in the arguments as an [input object type](https://graphql.org/graphql-js/mutations-and-input-types/)._
166166

167+
- `addLimitArgument` (type: `boolean`, default: `false`): Add a `limit` argument to fields returning lists of objects/lists that will limit the number of returned elements, selecting the first `n` elements of the list.
168+
167169
Consider this example of passing options:
168170

169171
```javascript

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

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

0 commit comments

Comments
 (0)