Skip to content

Commit bbae892

Browse files
elsmrAlan-Cha
authored andcommitted
Add test for parameter types
Signed-off-by: Elias Meire <elias@meire.dev>
1 parent be15d35 commit bbae892

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict'
22

33
import { beforeAll, describe, test, expect } from '@jest/globals'
4-
import { GraphQLEnumType, GraphQLObjectType, GraphQLSchema } from 'graphql'
4+
import {
5+
GraphQLEnumType,
6+
GraphQLInputObjectType,
7+
GraphQLObjectType,
8+
GraphQLSchema
9+
} from 'graphql'
510

611
import * as openAPIToGraphQL from '../lib/index'
712
import { Oas3 } from '../lib/types/oas3'
@@ -76,6 +81,13 @@ describe('GraphQL Extensions', () => {
7681
expect(fields).toContain('orderPet')
7782
expect(order.getFields().orderPet.type.toString()).toEqual('Pet')
7883
})
84+
85+
test('should rename Parameters with x-graphql-type-name', () => {
86+
const renamedType = createdSchema.getType('Meta')
87+
expect(renamedType).toBeInstanceOf(GraphQLInputObjectType)
88+
expect(createdSchema.getType('AdditionalMetadata')).toBeUndefined()
89+
expect(createdSchema.getType('AdditionalMetadataInput')).toBeUndefined()
90+
})
7991
})
8092

8193
describe('Error handling', () => {

packages/openapi-to-graphql/test/fixtures/extensions.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,21 @@
526526
"description": "The password for login in clear text",
527527
"required": false,
528528
"schema": { "type": "string" }
529+
},
530+
{
531+
"name": "additionalMetadata",
532+
"in": "query",
533+
"description": "Additional metadata",
534+
"required": false,
535+
"schema": {
536+
"type": "object",
537+
"x-graphql-type-name": "Meta",
538+
"properties": {
539+
"test": {
540+
"type": "string"
541+
}
542+
}
543+
}
529544
}
530545
],
531546
"responses": {

0 commit comments

Comments
 (0)