-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support GraphQLID #191
Support GraphQLID #191
Conversation
@omarchehab98 Thank you so much for this PR, very interesting proposal! We are not perfectly familiar with the way that id / uuid formatting works in OpenAPI / JSON schema. Maybe you can help us? For one, you make a check for Furthermore, we couldn't find reference to the |
@ErikWittern format id and uuid are undefined by the openapi spec. format uuid was given as an example of undefined formats that may be used. Since we know uuid follows a strict format, I also wanted to a more generic format. Thus I chose another undefined format called id. It follows no format, we can let the user define it. I agree with your concern about format uuid, I can amend that. Finally, regarding format id, I don't plan on adding any constraints. It seems like the tests didn't like it being a number but I recommend we explore that further. Perhaps it's good that we enforce it being a string because of number precision variation in different languages and computers and given that it is generally not helpful to do arithmetic on an id with the exception of hashing. |
Please feel free to take the lead from here, I don't mind if you jump in, make changes, and merge it |
@omarchehab98 Thanks for the quick response! And thanks again for filing the issue and the very detailed PR, all highly appreciated. I think we need to enforce that the ID field should be a string. Your logic regarding number precision variation makes a lot of sense. Also, the ID scalar in GraphQL expects the JSON value to be a string. However, I do not think we should add our own custom I can fix the tests and help amend the commit as soon as I am free. |
Is this PR on your radar to merge? |
Yes! I think we should! I made some changes and added test cases since the last time we spoke. We are still missing the option to declare other ID formats (and exposing it in the CLI) though. |
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]>
@omarchehab98 @Alan-Cha Great work, thank you! |
Closes: #187
Summary:
Adds support to specifying a field being of type GraphQLID. Add
format: id
orformat: uuid
.Test Plan:
packages/openapi-to-graphql
npm run start_dev
Before:
After:
Before:
After:
Before:
After: