Skip to content

Commit

Permalink
test: Update introspection fixtures to avoid as const
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jan 22, 2024
1 parent d29ed37 commit 2601bd8
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion scripts/eslint-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
extends: ['prettier'],
plugins: ['prettier', 'tsdoc'],
ignorePatterns: ['node_modules/', 'dist/', 'coverage/', 'perf/'],
ignorePatterns: ['node_modules/', 'dist/', 'coverage/', 'perf/', 'fixtures'],
rules: {
'no-undef': 'off',
'no-empty': 'off',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/api.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Document', () => {
import { simpleIntrospection } from './simpleIntrospection';
import { ResultOf, initGraphQLTada, readFragment } from './api';
const graphql = initGraphQLTada<{ introspection: typeof simpleIntrospection; }>();
const graphql = initGraphQLTada<{ introspection: simpleIntrospection; }>();
const todoFragment = graphql(\`
fragment TodoData on Todo {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/api.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type value = { __value: true };
type data = { __data: true };

describe('Public API', () => {
const graphql = initGraphQLTada<{ introspection: typeof simpleIntrospection }>();
const graphql = initGraphQLTada<{ introspection: simpleIntrospection }>();

it('should create a fragment mask on masked fragments', () => {
const fragment = graphql(`
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const testTypeHost = test.each([

describe('graphql function', () => {
it('should strip @_unmask from fragment documents', () => {
const graphql = initGraphQLTada<{ introspection: typeof simpleIntrospection }>();
const graphql = initGraphQLTada<{ introspection: simpleIntrospection }>();

const todoFragment = graphql(`
fragment TodoData on Todo @_unmask {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('declare setupSchema configuration', () => {
declare module './api' {
interface setupSchema {
introspection: typeof simpleIntrospection;
introspection: simpleIntrospection;
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('initGraphQLTada configuration', () => {
import { ResultOf, FragmentOf, initGraphQLTada, readFragment } from './api';
import { $tada } from './namespace';
const graphql = initGraphQLTada<{ introspection: typeof simpleIntrospection; }>();
const graphql = initGraphQLTada<{ introspection: simpleIntrospection; }>();
const todoFragment = graphql(\`
fragment TodoData on Todo {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('initGraphQLTada configuration', () => {
import { ResultOf, FragmentOf, initGraphQLTada, readFragment } from './api';
import { $tada } from './namespace';
const graphql = initGraphQLTada<{ introspection: typeof simpleIntrospection; }>();
const graphql = initGraphQLTada<{ introspection: simpleIntrospection; }>();
const todoFragment = graphql(\`
fragment TodoData on Todo @_unmask {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/fixtures/githubIntrospection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const githubIntrospection = {
export type githubIntrospection = {
__schema: {
queryType: {
name: 'Query',
Expand Down Expand Up @@ -155821,4 +155821,4 @@ export const githubIntrospection = {
},
],
},
} as const;
};
4 changes: 2 additions & 2 deletions src/__tests__/fixtures/simpleIntrospection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const simpleIntrospection = {
export type simpleIntrospection = {
__schema: {
queryType: {
name: 'Query',
Expand Down Expand Up @@ -588,4 +588,4 @@ export const simpleIntrospection = {
},
],
},
} as const;
};
4 changes: 2 additions & 2 deletions src/__tests__/introspection.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Introspection', () => {
import { simpleIntrospection } from './simpleIntrospection';
import { mapIntrospection } from './introspection';
type schema = mapIntrospection<typeof simpleIntrospection>;
type schema = mapIntrospection<simpleIntrospection>;
`,
});

Expand All @@ -38,7 +38,7 @@ describe('Introspection', () => {
import { githubIntrospection } from './githubIntrospection';
import type { mapIntrospection } from './introspection';
type schema = mapIntrospection<typeof githubIntrospection>;
type schema = mapIntrospection<githubIntrospection>;
`,
});

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/introspection.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { simpleSchema } from './fixtures/simpleSchema';
import type { mapIntrospection } from '../introspection';

test('prepares sample schema', () => {
type expected = mapIntrospection<typeof simpleIntrospection>;
type expected = mapIntrospection<simpleIntrospection>;
expectTypeOf<expected>().toMatchTypeOf<simpleSchema>();
});

test('applies scalar types as appropriate', () => {
type expected = mapIntrospection<typeof simpleIntrospection, { ID: 'ID' }>;
type expected = mapIntrospection<simpleIntrospection, { ID: 'ID' }>;

type idScalar = expected['types']['ID']['type'];
expectTypeOf<idScalar>().toEqualTypeOf<'ID'>();
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/selection.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ test('infers __typename on union unambiguously', () => {
});

test('infers queries from GitHub introspection schema', () => {
type schema = mapIntrospection<
typeof import('./fixtures/githubIntrospection').githubIntrospection
>;
type schema = mapIntrospection<import('./fixtures/githubIntrospection').githubIntrospection>;

type repositories = parseDocument</* GraphQL */ `
query ($org: String!, $repo: String!) {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('simple introspection', () => {
}
\`>;
type schema = mapIntrospection<typeof simpleIntrospection>;
type schema = mapIntrospection<simpleIntrospection>;
type actual = getDocumentType<query, schema>;
expectTypeOf<{
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('simple introspection', () => {
}
\`>;
type schema = mapIntrospection<typeof simpleIntrospection>;
type schema = mapIntrospection<simpleIntrospection>;
type actual = getDocumentType<query, schema>;
expectTypeOf<{
Expand Down
13 changes: 5 additions & 8 deletions src/__tests__/variables.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { expectTypeOf, test } from 'vitest';
import type { simpleIntrospection } from './fixtures/simpleIntrospection';
import type { simpleSchema as schema } from './fixtures/simpleSchema';
import type { parseDocument } from '../parser';
import type { mapIntrospection } from '../introspection';
import type { getVariablesType } from '../variables';

type introspection = mapIntrospection<typeof simpleIntrospection>;

test('parses document-variables correctly', () => {
const query = `
mutation ($id: ID!) {
Expand All @@ -14,7 +11,7 @@ test('parses document-variables correctly', () => {
`;

type doc = parseDocument<typeof query>;
type variables = getVariablesType<doc, introspection>;
type variables = getVariablesType<doc, schema>;

expectTypeOf<variables>().toEqualTypeOf<{ id: string | number }>();
});
Expand All @@ -27,7 +24,7 @@ test('works for input-objects', () => {
`;

type doc = parseDocument<typeof query>;
type variables = getVariablesType<doc, introspection>;
type variables = getVariablesType<doc, schema>;

expectTypeOf<variables>().toEqualTypeOf<{
id: string | number;
Expand All @@ -43,7 +40,7 @@ test('allows optionals for default values', () => {
`;

type doc = parseDocument<typeof query>;
type variables = getVariablesType<doc, introspection>;
type variables = getVariablesType<doc, schema>;

expectTypeOf<variables>().toEqualTypeOf<{ id?: string | number | undefined }>();
expectTypeOf<variables['id']>().toEqualTypeOf<string | number | undefined>();
Expand All @@ -57,7 +54,7 @@ test('allows optionals for nullable values', () => {
`;

type doc = parseDocument<typeof query>;
type variables = getVariablesType<doc, introspection>;
type variables = getVariablesType<doc, schema>;

expectTypeOf<variables>().toEqualTypeOf<{ id?: string | number | null | undefined }>();
expectTypeOf<variables['id']>().toEqualTypeOf<string | number | null | undefined>();
Expand Down

0 comments on commit 2601bd8

Please sign in to comment.