Skip to content

Commit

Permalink
Rename tada namespace to $tada to indicate it's private
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jan 10, 2024
1 parent 4ef0bdd commit 0f131b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/selection.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectTypeOf, test } from 'vitest';
import { simpleSchema } from './fixtures/simpleSchema';
import { tada } from '../namespace';
import { $tada } from '../namespace';
import { parseDocument } from '../parser';
import { mapIntrospection } from '../introspection';
import { getDocumentType } from '../selection';
Expand Down Expand Up @@ -116,7 +116,7 @@ test('infers fragment spreads for fragment refs', () => {
type fragment = parseDocument</* GraphQL */ `
fragment Fields on Todo { id text __typename }
`>['definitions'][0] & {
[tada.fragmentName]: 'Fields';
[$tada.fragmentName]: 'Fields';
};

type query = parseDocument</* GraphQL */ `
Expand All @@ -127,7 +127,7 @@ test('infers fragment spreads for fragment refs', () => {

type expected = {
todos: Array<{
[tada.fragmentRefs]: {
[$tada.fragmentRefs]: {
Fields: fragment;
};
} | null> | null;
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export type { tada } from './namespace';

export * from './api';
12 changes: 10 additions & 2 deletions src/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
declare namespace tada {
/** Private namespace holding our symbols for markers.
*
* @remarks
* Markers are used to indicate, for example, which fragments a given GraphQL document
* is referring to or which fragments a document exposes. This ties into “fragment masking”,
* a process by which the type of a fragment is hidden away until it’s unwrapped, to enforce
* isolation and code-reuse.
*/
declare namespace $tada {
const fragmentRefs: unique symbol;
export type fragmentRefs = typeof fragmentRefs;

const fragmentName: unique symbol;
export type fragmentName = typeof fragmentName;
}

export type { tada };
export type { $tada };
6 changes: 3 additions & 3 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
NameNode,
} from '@0no-co/graphql.web';

import type { tada } from './namespace';
import type { $tada } from './namespace';
import type { obj, objValues } from './utils';
import type { getFragmentMap } from './fragments';
import type { DocumentNodeLike } from './parser';
Expand Down Expand Up @@ -82,9 +82,9 @@ type getFragmentSelection<
: Node extends { kind: Kind.FRAGMENT_SPREAD; name: any }
? Node['name']['value'] extends keyof Fragments
? Fragments[Node['name']['value']] extends infer Fragment extends {
[tada.fragmentName]: string;
[$tada.fragmentName]: string;
}
? { [tada.fragmentRefs]: { [Name in Fragment[tada.fragmentName]]: Fragment } }
? { [$tada.fragmentRefs]: { [Name in Fragment[$tada.fragmentName]]: Fragment } }
: getSelection<
Fragments[Node['name']['value']]['selectionSet']['selections'],
Type,
Expand Down

0 comments on commit 0f131b0

Please sign in to comment.