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

fix(internal): Fix loaders not fetching subscriptionType #172

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-bees-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gql.tada/internal": patch
---

Fix `subscriptionType` not being fetched during introspection.
334 changes: 334 additions & 0 deletions packages/internal/src/loaders/__tests__/query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,334 @@
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,
};

const output = print(makeIntrospectionQuery(support));

expect(output).toMatch(/isRepeatable/);
expect(output).toMatch(/specifiedByURL/);
expect(output).toMatch(/inputFields\(includeDeprecated: true\)/);

expect(output).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,
};

const output = print(makeIntrospectionQuery(support));

expect(output).not.toMatch(/isRepeatable/);
expect(output).not.toMatch(/specifiedByURL/);
expect(output).not.toMatch(/inputFields\(includeDeprecated: true\)/);

expect(output).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
}
}
}
}
}
}
}
}
}
}"
`);
});
});
2 changes: 1 addition & 1 deletion packages/internal/src/loaders/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const _makeSchemaSelection = (support: SupportedFeatures): SelectionSetNode => (
// subscriptionType { name }
{
kind: Kind.FIELD,
name: { kind: Kind.NAME, value: 'mutationType' },
name: { kind: Kind.NAME, value: 'subscriptionType' },
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
Expand Down
Loading