Skip to content

Commit e744a45

Browse files
omarchehab98ErikWittern
authored andcommitted
Support GraphQLID
Closes: #187 Summary: Adds support to specifying a field being of type GraphQLID. Add `format: id` or `format: uuid`. Test Plan: 1. Change directory to `packages/openapi-to-graphql` 2. Run `npm run start_dev` 3. Browse to localhost:3000/graphql 4. Click on "Docs" 5. Click on "Query" 6. Observe the type of properties whose names end with "id" Before: company(id: String!): Company office(accept: Accept, id: Int!): Office productWithId(productId: String!, productTag: String!): ProductWithId productsReviews(id: String!, limit: Int, productTag: String): [ProductsReviewsListItem] After: company(id: ID!): Company office(accept: Accept, id: ID!): Office productWithId(productId: ID!, productTag: String!): ProductWithId productsReviews(id: ID!, limit: Int, productTag: String): [ProductsReviewsListItem] 7. Click on "Company" 8. Observe the type of "id" Before: id: String The identifier of a company After: id: ID The identifier of a company 9. Click "Back" twice 10. Click on "Mutation" 11. Click on "ProductWithIdInput" 12. Observe the type of "productId" Before: productId: String The id of the product After: productId: ID The id of the product Signed-off-by: Omar Chehab <[email protected]>
1 parent 78feac0 commit e744a45

23 files changed

+212
-77
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"test": "cd packages/openapi-to-graphql/ && npm test"
66
},
77
"devDependencies": {
8-
"@types/jest": "^24.0.15",
8+
"@types/jest": "^24.0.16",
99
"graphql": "^14.0.2",
1010
"jest": "^24.8.0",
1111
"lerna": "^3.4.3",

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

100644100755
File mode changed.

packages/openapi-to-graphql/README.md

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

155155
- `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.
156156

157+
- `idFormats` (type: `string[]`): If a schema is of type string and has format UUID, it will be translated into a [GraphQL ID type](https://graphql.org/graphql-js/type/#graphqlid). To allow for more customzation, this option allows users to specify other formats that should be interpreted as ID types.
158+
157159
***
158160

159161
Resolver options:

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

Lines changed: 2 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/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/oas_3_tools.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export declare function instantiatePathAndGetQuery(path: string, parameters: Par
8686
* Returns the "type" of the given JSON schema. Makes best guesses if the type
8787
* is not explicitly defined.
8888
*/
89-
export declare function getSchemaType(schema: SchemaObject): string | null;
89+
export declare function getSchemaType(schema: SchemaObject, data: PreprocessingData): string | null;
9090
/**
9191
* Determines an approximate name for the resource at the given path.
9292
*/

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

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

packages/openapi-to-graphql/lib/oas_3_tools.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/preprocessor.js

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/preprocessor.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)