-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,322 @@ | ||
import { expect, describe, it } from 'vitest'; | ||
import { print } from '@0no-co/graphql.web'; | ||
|
||
import { makeIntrospectionQuery, makeIntrospectSupportQuery, toSupportedFeatures } from '../query'; | ||
|
||
describe('makeIntrospectSupportQuery', () => { | ||
it('prints to introspection support query', () => { | ||
expect(print(makeIntrospectSupportQuery())).toMatchInlineSnapshot(` | ||
"query IntrospectSupportQuery { | ||
directive: __type(name: "__Directive") { | ||
fields { | ||
name | ||
} | ||
} | ||
type: __type(name: "__Type") { | ||
fields { | ||
name | ||
} | ||
} | ||
inputValue: __type(name: "__InputValue") { | ||
fields { | ||
name | ||
} | ||
} | ||
}" | ||
`); | ||
}); | ||
}); | ||
|
||
describe('toSupportedFeatures', () => { | ||
it('outputs default with no features enabled', () => { | ||
expect(toSupportedFeatures({ type: null, inputValue: null, directive: null })).toEqual({ | ||
directiveIsRepeatable: false, | ||
specifiedByURL: false, | ||
inputValueDeprecation: false, | ||
}); | ||
}); | ||
|
||
it('detects `isRepeatable` support on directives', () => { | ||
const input = { | ||
type: null, // stubbed | ||
inputValue: null, // stubbed | ||
directive: { | ||
fields: [{ name: 'isRepeatable' }], | ||
}, | ||
}; | ||
|
||
expect(toSupportedFeatures(input)).toMatchObject({ | ||
directiveIsRepeatable: true, | ||
}); | ||
}); | ||
|
||
it('detects `specifiedByURL` support on scalars', () => { | ||
const input = { | ||
inputValue: null, // stubbed | ||
directive: null, // stubbed | ||
type: { | ||
fields: [{ name: 'specifiedByURL' }], | ||
}, | ||
}; | ||
|
||
expect(toSupportedFeatures(input)).toMatchObject({ | ||
specifiedByURL: true, | ||
}); | ||
}); | ||
|
||
it('detects `isDeprecated` support on input values', () => { | ||
const input = { | ||
type: null, // stubbed | ||
directive: null, // stubbed | ||
inputValue: { | ||
fields: [{ name: 'isDeprecated' }], | ||
}, | ||
}; | ||
|
||
expect(toSupportedFeatures(input)).toMatchObject({ | ||
inputValueDeprecation: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('makeIntrospectionQuery', () => { | ||
it('correctly outputs introspection query with all features enabled', () => { | ||
const support = { | ||
directiveIsRepeatable: true, | ||
specifiedByURL: true, | ||
inputValueDeprecation: true, | ||
}; | ||
|
||
expect(print(makeIntrospectionQuery(support))).toMatchInlineSnapshot(` | ||
"query IntrospectionQuery { | ||
__schema { | ||
queryType { | ||
name | ||
} | ||
mutationType { | ||
name | ||
} | ||
subscriptionType { | ||
name | ||
} | ||
types { | ||
...FullType | ||
} | ||
directives { | ||
name | ||
description | ||
locations | ||
args(includeDeprecated: true) { | ||
...InputValue | ||
} | ||
isRepeatable | ||
} | ||
} | ||
} | ||
fragment FullType on __Type { | ||
kind | ||
name | ||
description | ||
specifiedByURL | ||
fields(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
args(includeDeprecated: true) { | ||
...InputValue | ||
} | ||
type { | ||
...TypeRef | ||
} | ||
} | ||
interfaces { | ||
...TypeRef | ||
} | ||
possibleTypes { | ||
...TypeRef | ||
} | ||
inputFields(includeDeprecated: true) { | ||
...InputValue | ||
} | ||
enumValues(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
} | ||
} | ||
fragment InputValue on __InputValue { | ||
name | ||
description | ||
defaultValue | ||
type { | ||
...TypeRef | ||
} | ||
isDeprecated | ||
deprecationReason | ||
} | ||
fragment TypeRef on __Type { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}" | ||
`); | ||
}); | ||
|
||
it('correctly outputs introspection query with all features disabled', () => { | ||
const support = { | ||
directiveIsRepeatable: false, | ||
specifiedByURL: false, | ||
inputValueDeprecation: false, | ||
}; | ||
|
||
expect(print(makeIntrospectionQuery(support))).toMatchInlineSnapshot(` | ||
"query IntrospectionQuery { | ||
__schema { | ||
queryType { | ||
name | ||
} | ||
mutationType { | ||
name | ||
} | ||
subscriptionType { | ||
name | ||
} | ||
types { | ||
...FullType | ||
} | ||
directives { | ||
name | ||
description | ||
locations | ||
args { | ||
...InputValue | ||
} | ||
} | ||
} | ||
} | ||
fragment FullType on __Type { | ||
kind | ||
name | ||
description | ||
fields(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
args { | ||
...InputValue | ||
} | ||
type { | ||
...TypeRef | ||
} | ||
} | ||
interfaces { | ||
...TypeRef | ||
} | ||
possibleTypes { | ||
...TypeRef | ||
} | ||
inputFields { | ||
...InputValue | ||
} | ||
enumValues(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
} | ||
} | ||
fragment InputValue on __InputValue { | ||
name | ||
description | ||
defaultValue | ||
type { | ||
...TypeRef | ||
} | ||
} | ||
fragment TypeRef on __Type { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
ofType { | ||
kind | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}" | ||
`); | ||
}); | ||
}); |