Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gql.tada

Package Overview
Dependencies
Maintainers
1
Versions
234
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql.tada - npm Package Compare versions

Comparing version 1.1.1-canary-caa94dc0f10b22d8bf6d418eb23e14f1a586b416 to 1.2.0-canary-08e1b46a85dce0345c6842577fed5966475c5b0d

169

dist/gql-tada.d.ts

@@ -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 = {

@@ -938,2 +962,13 @@ [name: string]: any;

: never;
type omitFragmentRefsRec<Data> = Data extends readonly (infer Value)[]
? readonly omitFragmentRefsRec<Value>[]
: Data extends null
? null
: Data extends undefined
? undefined
: Data extends {}
? {
[Key in Exclude<keyof Data, $tada.fragmentRefs>]: omitFragmentRefsRec<Data[Key]>;
}
: Data;
type makeUndefinedFragmentRef<FragmentName extends string> = {

@@ -1458,2 +1493,39 @@ [$tada.fragmentRefs]: {

): 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>;
}

@@ -1601,2 +1673,14 @@ type schemaOfConfig<Setup extends AbstractSetupSchema> = mapIntrospection<

: Data;
type fragmentRefsOfFragmentsRec<Fragments extends readonly any[]> = Fragments extends readonly [
infer Fragment,
...infer Rest,
]
? obj<makeFragmentRef<Fragment> & fragmentRefsOfFragmentsRec<Rest>>
: {};
type resultOfFragmentsRec<Fragments extends readonly any[]> = Fragments extends readonly [
infer Fragment,
...infer Rest,
]
? ResultOf<Fragment> & resultOfFragmentsRec<Rest>
: {};
type fragmentOfTypeRec<Document extends makeDefinitionDecoration> =

@@ -1607,2 +1691,3 @@ | readonly fragmentOfTypeRec<Document>[]

| null;
type resultOfTypeRec<Data> = readonly resultOfTypeRec<Data>[] | Data | undefined | null;
/** Unmasks a fragment mask for a given fragment document and data.

@@ -1665,2 +1750,84 @@ *

: mirrorFragmentTypeRec<Fragment, ResultOf<Document>>;
/** For testing, masks fragment data for given data and fragments.
*
* @param _fragments - A list of GraphQL documents of fragments, created using {@link graphql}.
* @param data - The combined result data of the fragments, which can be wrapped in arrays.
* @returns The masked data of the fragments.
*
* @remarks
* When creating test data, you may define data for fragments that’s unmasked, making it
* unusable in parent fragments or queries that require masked data.
*
* This means that you may have to use {@link maskFragments} to mask your data first
* for TypeScript to not report an error.
*
* @example
* ```
* import { FragmentOf, ResultOf, graphql, maskFragments } from 'gql.tada';
*
* const bookFragment = graphql(`
* fragment BookComponent on Book {
* id
* title
* }
* `);
*
* const data = maskFragments([bookFragment], { id: 'id', title: 'book' });
* ```
*
* @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)
*/
declare function maskFragments<
const Fragments extends readonly [...makeDefinitionDecoration[]],
const Data extends resultOfTypeRec<resultOfFragmentsRec<Fragments>>,
>(
_fragments: Fragments,
data: Data
): resultOfTypeRec<resultOfFragmentsRec<Fragments>> extends Data
? never
: mirrorFragmentTypeRec<Data, fragmentRefsOfFragmentsRec<Fragments>>;
/** For testing, converts document data without fragment refs to their result type.
*
* @param _document - A GraphQL document, created using {@link graphql}.
* @param data - The result data of the GraphQL document with optional fragment refs.
* @returns The masked result data of the document.
*
* @remarks
* When creating test data, you may define data for documents that’s unmasked, but
* need to cast the data to match the result type of your document.
*
* This means that you may have to use {@link unsafe_readResult} to cast
* them to the result type, instead of doing `as any as ResultOf<typeof document>`.
*
* This function is inherently unsafe, since it doesn't check that your document
* actually contains the masked fragment data!
*
* @example
* ```
* import { FragmentOf, ResultOf, graphql, unsafe_readResult } from 'gql.tada';
*
* const bookFragment = graphql(`
* fragment BookComponent on Book {
* id
* title
* }
* `);
*
* const query = graphql(`
* query {
* book {
* ...BookComponent
* }
* }
* `, [bookFragment]);
*
* const data = unsafe_readResult(query, { book: { id: 'id', title: 'book' } });
* ```
*
* @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)
*/
declare function unsafe_readResult<
const Document extends DocumentDecoration<any, any>,
const Data extends omitFragmentRefsRec<ResultOf<Document>>,
>(_document: Document, data: Data): ResultOf<Document>;
declare const graphql: GraphQLTadaAPI<schemaOfConfig<setupSchema>>;

@@ -1677,2 +1844,3 @@

initGraphQLTada,
maskFragments,
parse,

@@ -1682,2 +1850,3 @@ type parseDocument,

type setupSchema,
unsafe_readResult,
};

34

dist/gql-tada.js

@@ -8,21 +8,25 @@ Object.defineProperty(exports, "__esModule", {

function initGraphQLTada() {
return function graphql(e, i) {
var a = r.parse(e).definitions;
var n = new Set;
for (var t of i || []) {
for (var d of t.definitions) {
if (d.kind === r.Kind.FRAGMENT_DEFINITION && !n.has(d)) {
a.push(d);
n.add(d);
function graphql(e, a) {
var n = r.parse(e).definitions;
var i = new Set;
for (var t of a || []) {
for (var s of t.definitions) {
if (s.kind === r.Kind.FRAGMENT_DEFINITION && !i.has(s)) {
n.push(s);
i.add(s);
}
}
}
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;
}

@@ -36,2 +40,6 @@

exports.maskFragments = function maskFragments(r, e) {
return e;
};
exports.parse = function parse(e) {

@@ -44,2 +52,6 @@ return r.parse(e);

};
exports.unsafe_readResult = function unsafe_readResult(r, e) {
return e;
};
//# sourceMappingURL=gql-tada.js.map
{
"name": "gql.tada",
"description": "The spec-compliant & magical GraphQL query language engine in the TypeScript type system",
"version": "1.1.1-canary-caa94dc0f10b22d8bf6d418eb23e14f1a586b416",
"version": "1.2.0-canary-08e1b46a85dce0345c6842577fed5966475c5b0d",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc