Comparing version 1.2.0-canary-5ec863cff8c6951ca027e62b08949098f862085e to 1.2.0
@@ -157,2 +157,3 @@ import { Kind, OperationTypeNode, DocumentNode } from '@0no-co/graphql.web'; | ||
kind: 'SCALAR'; | ||
name: Type['name']; | ||
type: Type['name'] extends keyof Scalars | ||
@@ -258,2 +259,25 @@ ? Scalars[Type['name']] | ||
}; | ||
type getScalarTypeNames<Schema extends IntrospectionLikeType> = | ||
Schema['types'][keyof Schema['types']] extends infer Type | ||
? Type extends { | ||
kind: 'SCALAR' | 'ENUM'; | ||
name: any; | ||
} | ||
? Type['name'] | ||
: never | ||
: never; | ||
type getScalarType$1< | ||
Schema extends IntrospectionLikeType, | ||
Name extends keyof Schema['types'], | ||
> = Schema['types'][Name] extends { | ||
kind: 'SCALAR'; | ||
type: infer Type; | ||
} | ||
? Type | ||
: Schema['types'][Name] extends { | ||
kind: 'ENUM'; | ||
type: infer Type; | ||
} | ||
? Type | ||
: never; | ||
type ScalarsLike = { | ||
@@ -1468,2 +1492,39 @@ [name: string]: any; | ||
): getDocumentNode<parseDocument<In>, Schema, getFragmentsOfDocumentsRec<Fragments>>; | ||
/** Function to validate the type of a given scalar or enum value. | ||
* | ||
* @param name - The name of a scalar or enum type. | ||
* @param value - An optional scalar value of the given type. | ||
* @returns A {@link DocumentNode} with result and variables types. | ||
* | ||
* @remarks | ||
* This function validates that a value matches an enum or scalar type | ||
* as a type check. | ||
* | ||
* You can use it to retrieve the type of a given scalar or enum type | ||
* for use in a utility function or separate component that only | ||
* accepts a primitive scalar or enum value. | ||
* | ||
* Note that this function does not perform runtime checks of your | ||
* scalar value! | ||
* | ||
* @example | ||
* ``` | ||
* import { graphql } from 'gql.tada'; | ||
* | ||
* type myEnum = ReturnType<graphql.scalar<'myEnum'>>; | ||
* | ||
* const myEnumValue = graphql.scalar('myEnum', 'value'); | ||
* ``` | ||
*/ | ||
scalar< | ||
const Name extends getScalarTypeNames<Schema>, | ||
const Value extends getScalarType$1<Schema, Name> | null | undefined, | ||
>( | ||
name: Name, | ||
value: Value | ||
): Value; | ||
scalar<const Name extends getScalarTypeNames<Schema>>( | ||
name: Name, | ||
value: getScalarType$1<Schema, Name> | ||
): getScalarType$1<Schema, Name>; | ||
} | ||
@@ -1470,0 +1531,0 @@ type schemaOfConfig<Setup extends AbstractSetupSchema> = mapIntrospection< |
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "__esModule", { | ||
function initGraphQLTada() { | ||
return function graphql(e, n) { | ||
var a = r.parse(e).definitions; | ||
function graphql(e, a) { | ||
var n = r.parse(e).definitions; | ||
var i = new Set; | ||
for (var t of n || []) { | ||
for (var t of a || []) { | ||
for (var s of t.definitions) { | ||
if (s.kind === r.Kind.FRAGMENT_DEFINITION && !i.has(s)) { | ||
a.push(s); | ||
n.push(s); | ||
i.add(s); | ||
@@ -20,10 +20,14 @@ } | ||
} | ||
if (a[0].kind === r.Kind.FRAGMENT_DEFINITION && a[0].directives) { | ||
a[0].directives = a[0].directives.filter((r => "_unmask" !== r.name.value)); | ||
if (n[0].kind === r.Kind.FRAGMENT_DEFINITION && n[0].directives) { | ||
n[0].directives = n[0].directives.filter((r => "_unmask" !== r.name.value)); | ||
} | ||
return { | ||
kind: r.Kind.DOCUMENT, | ||
definitions: a | ||
definitions: n | ||
}; | ||
} | ||
graphql.scalar = function scalar(r, e) { | ||
return e; | ||
}; | ||
return graphql; | ||
} | ||
@@ -30,0 +34,0 @@ |
{ | ||
"name": "gql.tada", | ||
"description": "The spec-compliant & magical GraphQL query language engine in the TypeScript type system", | ||
"version": "1.2.0-canary-5ec863cff8c6951ca027e62b08949098f862085e", | ||
"version": "1.2.0", | ||
"author": "0no.co <hi@0no.co>", | ||
@@ -6,0 +6,0 @@ "source": "./src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
103172
1921
1