-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: client layer property modules (#1118)
- Loading branch information
1 parent
ca12b80
commit f339f7b
Showing
31 changed files
with
481 additions
and
389 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
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
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
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,2 @@ | ||
export * from './document.js' | ||
export * from './print.js' |
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 @@ | ||
export * as Document from './_.js' |
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,42 @@ | ||
import { type OperationType, type RootTypeNameMutation, type RootTypeNameQuery } from '../../lib/graphql.js' | ||
import type { FirstNonUnknownNever, IsKeyInObjectOptional, Values } from '../../lib/prelude.js' | ||
|
||
export type OperationName = string | ||
|
||
export interface SomeDocumentOperation { | ||
[k: string]: object | ||
} | ||
|
||
export interface SomeDocument { | ||
mutation?: SomeDocumentOperation | ||
query?: SomeDocumentOperation | ||
} | ||
|
||
// // dprint-ignore | ||
// type IsHasMultipleOperations<$Document extends SomeDocument> = | ||
// All<[ | ||
// IsHasMultipleKeys<$Document[OperationType.Query]>, | ||
// IsHasMultipleKeys<$Document[OperationType.Mutation]>, | ||
// ]> | ||
|
||
// dprint-ignore | ||
export type GetOperationNames<$Document extends SomeDocument> = Values< | ||
{ | ||
[$OperationType in keyof $Document]: keyof $Document[$OperationType] & string | ||
} | ||
> | ||
|
||
// dprint-ignore | ||
export type GetRootTypeNameOfOperation<$Document extends SomeDocument, $Name extends OperationName> = | ||
IsKeyInObjectOptional<$Document[OperationType.Mutation], $Name> extends true ? RootTypeNameMutation : | ||
IsKeyInObjectOptional<$Document[OperationType.Query], $Name> extends true ? RootTypeNameQuery : | ||
never | ||
|
||
// dprint-ignore | ||
export type GetOperation<$Document extends SomeDocument, $Name extends string> = | ||
FirstNonUnknownNever<[ | ||
// @ts-expect-error could be unknown | ||
$Document[OperationType.Mutation][$Name], | ||
// @ts-expect-error could be unknown | ||
$Document[OperationType.Query][$Name] | ||
]> |
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,39 @@ | ||
import { operationTypeNameToRootTypeName, OperationTypes } from '../../lib/graphql.js' | ||
import { SelectionSet } from '../2_SelectionSet/__.js' | ||
import type { Context, DocumentObject } from '../2_SelectionSet/print.js' | ||
|
||
// todo this is currently unused by graffle internally. Remove? | ||
export const print = ( | ||
context: Context, | ||
document: DocumentObject, | ||
) => { | ||
const operations = [ | ||
...(Object.entries(document.query || {}).map(([operationName, selectionSet]) => ({ | ||
operationName, | ||
selectionSet, | ||
operationType: OperationTypes.query, | ||
}))), | ||
...(Object.entries(document.mutation || {}).map(([operationName, selectionSet]) => ({ | ||
operationName, | ||
selectionSet, | ||
operationType: OperationTypes.mutation, | ||
}))), | ||
] | ||
|
||
return operations.map(({ operationName, selectionSet, operationType }) => { | ||
const rootType = operationTypeNameToRootTypeName[operationType] | ||
const rootTypeDocument = selectionSet | ||
|
||
const schemaRootType = context.schemaIndex[`Root`][rootType] | ||
if (!schemaRootType) throw new Error(`Schema has no ${rootType} root type`) | ||
|
||
const documentString = SelectionSet.Print.resolveRootType( | ||
context, | ||
schemaRootType, | ||
rootTypeDocument, | ||
operationName, | ||
) | ||
|
||
return documentString | ||
}).join(`\n\n`) | ||
} |
Oops, something went wrong.