Skip to content
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

Supporting GraphQLID #187

Closed
omarchehab98 opened this issue Jul 1, 2019 · 1 comment · Fixed by #191
Closed

Supporting GraphQLID #187

omarchehab98 opened this issue Jul 1, 2019 · 1 comment · Fixed by #191
Labels
enhancement New feature or request

Comments

@omarchehab98
Copy link
Contributor

ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.
https://graphql.org/learn/schema/#scalar-types

Support emitting GraphQLID (https://graphql.org/graphql-js/type/#graphqlid)

Implementation Details

I peeped around the codebase, here are some ideas I got:

File schema_builder.ts, function getScalarType, add

    case 'id':
      def.ot = GraphQLID // TODO: Update import {GraphQLID} from 'graphql'
      break

File oas_3_tools.ts, function getSchemaType, add something along the lines of:

  // CASE: id
  if (schema.format === 'graphql-id') {
    return 'id'
  }
@Alan-Cha
Copy link
Collaborator

Alan-Cha commented Jul 1, 2019

Ah! This is a great change! Thank you so much! Will take a look into it.

@Alan-Cha Alan-Cha added the enhancement New feature or request label Jul 12, 2019
ErikWittern pushed a commit that referenced this issue Aug 7, 2019
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants