Skip to content

Commit

Permalink
chore(core): remove global context
Browse files Browse the repository at this point in the history
  • Loading branch information
Teages committed Sep 16, 2024
1 parent 401c4f2 commit 1278757
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
5 changes: 0 additions & 5 deletions packages/core/src/runtime/context.ts

This file was deleted.

8 changes: 2 additions & 6 deletions packages/core/src/runtime/query-func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { parseVariables } from './variable'
import type { DirectivesInputWithDollar } from './directive'
import { parseDirective } from './directive'
import { initDirectiveDollar } from './dollar'
import type { Context } from './context'

export function gqfn(
selection: TypeSelection<EmptyRecord>,
Expand Down Expand Up @@ -82,11 +81,8 @@ function graphQueryFunction<
const directivesNodes = parseDirective(directives(initDirectiveDollar()))

const definitions: DefinitionNode[] = []
const ctx: Context = {
pushDefinitionNode: node => definitions.push(node),
}

ctx.pushDefinitionNode({
definitions.push({
kind: Kind.OPERATION_DEFINITION,
directives: directivesNodes,
operation: {
Expand All @@ -101,7 +97,7 @@ function graphQueryFunction<
value: operationName,
}
: undefined,
selectionSet: parseTypeSelection(selection, ctx),
selectionSet: parseTypeSelection(selection),
})

return {
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/runtime/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { DollarContext, DollarPayload, SelectionDollar } from './dollar'
import { initSelectionDollar } from './dollar'
import { parseArgs } from './arg'
import { parseDirective } from './directive'
import type { Context } from './context'

export type TypeSelection<Vars extends DollarPayload> = Array<
| SelectionField
Expand All @@ -30,7 +29,6 @@ export function parseTypeSelection<
Vars extends DollarPayload,
>(
selectionSet: TypeSelection<Vars>,
ctx: Context,
): SelectionSetNode {
const selects: SelectionObject<Vars> = {}
selectionSet.forEach((item) => {
Expand All @@ -49,7 +47,7 @@ export function parseTypeSelection<

const selections: Array<SelectionNode> = Object
.entries(selects)
.map(([key, select]) => parseSelectionSet(key, select, ctx))
.map(([key, select]) => parseSelectionSet(key, select))

// Empty selection set is not allowed
if (selections.length === 0) {
Expand Down Expand Up @@ -77,10 +75,9 @@ export function parseSelectionSet<
>(
key: string,
selection: SelectionSet<Vars>,
ctx: Context,
): SelectionNode {
const { args, directives, content } = parseSelectionFunc(selection)
const childNode = parseSelectionContext(content, ctx)
const childNode = parseSelectionContext(content)
const argNodes = parseArgs(args)
const directiveNodes = parseDirective(directives)

Expand Down Expand Up @@ -161,11 +158,10 @@ export function parseSelectionContext<
Vars extends DollarPayload,
>(
selectionSet: SelectionContext<Vars>,
context: Context,
): SelectionSetNode | undefined {
if (selectionSet === true) {
return undefined
}

return parseTypeSelection(selectionSet, context)
return parseTypeSelection(selectionSet)
}

0 comments on commit 1278757

Please sign in to comment.