Skip to content

Commit 7bbe9d0

Browse files
committed
Change input name from extension
Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
1 parent 3c1f295 commit 7bbe9d0

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

packages/openapi-to-graphql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ The `x-graphql-type-name`, `x-graphql-field-name`, and `x-graphql-enum-mapping`
248248

249249
The type and field names and enum values that OpenAPI-to-GraphQL generates may not be adequate or may not be consistent over different versions so this is a way to guarantee consistency.
250250

251-
`x-graphql-type-name` and `x-graphql-field-name` can be added to JSON schema to change the type name as well as change a field name.
251+
`x-graphql-type-name` and `x-graphql-field-name` can be added to JSON schema to change the type name as well as change a field name. OpenAPI-to-GraphQL will also use `x-graphql-type-name` to name input object types by appending `Input` to the end of the name.
252252

253253
```diff
254254
{

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

Lines changed: 20 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/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.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ export function createDataDef<TSource, TContext, TArgs>(
717717

718718
if (name === names.fromExtension) {
719719
saneName = name
720-
saneInputName = name
720+
saneInputName = name + 'Input'
721721
} else {
722722
// Store and sanitize the name
723723
saneName = !data.options.simpleNames

packages/openapi-to-graphql/test/extensions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe('GraphQL Extensions', () => {
8787
expect(order.getFields().orderPet.type.toString()).toEqual('Pet')
8888
})
8989

90-
test('should rename Parameters with x-graphql-type-name', () => {
91-
const renamedType = createdSchema.getType('Meta')
90+
test('should rename input object type with x-graphql-type-name and append input at the end', () => {
91+
const renamedType = createdSchema.getType('MetaInput')
9292
expect(renamedType).toBeInstanceOf(GraphQLInputObjectType)
9393
expect(createdSchema.getType('AdditionalMetadata')).toBeUndefined()
9494
expect(createdSchema.getType('AdditionalMetadataInput')).toBeUndefined()

0 commit comments

Comments
 (0)