{"version":3,"file":"gql-tada.mjs","sources":["../src/api.ts"],"sourcesContent":["import type { DocumentNode, DefinitionNode } from '@0no-co/graphql.web';\nimport { Kind, parse as _parse } from '@0no-co/graphql.web';\n\nimport type {\n  IntrospectionLikeInput,\n  ScalarsLike,\n  SchemaLike,\n  mapIntrospection,\n  addIntrospectionScalars,\n} from './introspection';\n\nimport type {\n  DefinitionDecoration,\n  FragmentShape,\n  getFragmentsOfDocuments,\n  decorateFragmentDef,\n  omitFragmentRefsRec,\n  makeFragmentRef,\n} from './namespace';\n\nimport type { getDocumentType } from './selection';\nimport type { parseDocument, DocumentNodeLike } from './parser';\nimport type { getVariablesType, getScalarType } from './variables';\nimport type { obj, matchOr, writable, DocumentDecoration } from './utils';\n\n/** Abstract configuration type input for your schema and scalars.\n *\n * @remarks\n * This is used either via {@link setupSchema} or {@link initGraphQLTada} to set\n * up your schema and scalars.\n *\n * The `scalars` option is optional and can be used to set up more scalars, apart\n * from the default ones (like: Int, Float, String, Boolean).\n * It must be an object map of scalar names to their desired TypeScript types.\n *\n * @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.\n * @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.\n */\ninterface AbstractSetupSchema {\n  introspection: IntrospectionLikeInput;\n  scalars?: ScalarsLike;\n  disableMasking?: boolean;\n}\n\n/** Abstract type for internal configuration\n * @internal\n */\ninterface AbstractConfig {\n  isMaskingDisabled: boolean;\n}\n\n/** This is used to configure gql.tada with your introspection data and scalars.\n *\n * @remarks\n * You may extend this interface via declaration merging with your {@link IntrospectionQuery}\n * data and optionally your scalars to get proper type inference.\n * This is done by declaring a declaration for it as per the following example.\n *\n * Configuring scalars is optional and by default the standard scalrs are already\n * defined.\n *\n * This will configure the {@link graphql} export to infer types from your schema.\n * Alternatively, you may call {@link initGraphQLTada} instead.\n *\n * @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.\n * @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.\n *\n * @example\n * ```\n * import type { myIntrospection } from './myIntrospection';\n *\n * declare module 'gql.tada' {\n *   interface setupSchema {\n *     introspection: typeof myIntrospection;\n *     scalars: {\n *       DateTime: string;\n *       Json: any;\n *     };\n *   }\n * }\n * ```\n */\ninterface setupSchema extends AbstractSetupSchema {\n  /*empty*/\n}\n\ninterface AbstractSetupCache {\n  readonly __cacheDisabled: unknown;\n  [key: string]: unknown;\n}\n\ninterface setupCache extends AbstractSetupCache {}\n\ninterface GraphQLTadaAPI<Schema extends SchemaLike, Config extends AbstractConfig> {\n  /** In \"multi-schema\" mode this identifies the schema.\n   * @internal */\n  readonly __name: Schema['name'];\n\n  /** Function to create and compose GraphQL documents with result and variable types.\n   *\n   * @param input - A string of a GraphQL document.\n   * @param fragments - An optional list of other GraphQL fragments created with this function.\n   * @returns A {@link DocumentNode} with result and variables types.\n   *\n   * @remarks\n   * This function creates a {@link DocumentNode} with result and variables types.\n   * It is used with your schema in {@link setupSchema} to create a result type\n   * of your queries, fragments, and variables.\n   *\n   * You can compose fragments into this function by passing them and a fragment\n   * mask will be created for them.\n   * When creating queries, the returned document of queries can be passed into GraphQL clients\n   * which will then automatically infer the result and variables types.\n   *\n   * @example\n   * ```\n   * import { graphql } from 'gql.tada';\n   *\n   * const bookFragment = graphql(`\n   *   fragment BookComponent on Book {\n   *     id\n   *     title\n   *   }\n   * `);\n   *\n   * const bookQuery = graphql(`\n   *   query Book ($id: ID!) {\n   *     book(id: $id) {\n   *       id\n   *       ...BookComponent\n   *     }\n   *   }\n   * `, [bookFragment]);\n   * ```\n   *\n   * @see {@link readFragment} for how to read from fragment masks.\n   */\n  <const In extends string, const Fragments extends readonly FragmentShape[]>(\n    input: In,\n    fragments?: Fragments\n  ): setupCache[In] extends DocumentNodeLike\n    ? unknown extends setupCache['__cacheDisabled']\n      ? setupCache[In]\n      : getDocumentNode<\n          parseDocument<In>,\n          Schema,\n          getFragmentsOfDocuments<Fragments>,\n          Config['isMaskingDisabled']\n        >\n    : getDocumentNode<\n        parseDocument<In>,\n        Schema,\n        getFragmentsOfDocuments<Fragments>,\n        Config['isMaskingDisabled']\n      >;\n\n  /** Function to validate the type of a given scalar or enum value.\n   *\n   * @param name - The name of a scalar or enum type.\n   * @param value - An optional scalar value of the given type.\n   * @returns A {@link DocumentNode} with result and variables types.\n   *\n   * @remarks\n   * This function validates that a value matches an enum or scalar type\n   * as a type check.\n   *\n   * You can use it to retrieve the type of a given scalar or enum type\n   * for use in a utility function or separate component that only\n   * accepts a primitive scalar or enum value.\n   *\n   * Note that this function does not perform runtime checks of your\n   * scalar value!\n   *\n   * @example\n   * ```\n   * import { graphql } from 'gql.tada';\n   *\n   * type myEnum = ReturnType<graphql.scalar<'myEnum'>>;\n   *\n   * const myEnumValue = graphql.scalar('myEnum', 'value');\n   * ```\n   */\n  scalar<const Name extends string, Value>(\n    name: Name,\n    value: getScalarType<Name, Schema> extends Value\n      ? Value & getScalarType<Name, Schema>\n      : getScalarType<Name, Schema>\n  ): Value;\n  scalar<const Name extends string, Value>(\n    name: Name,\n    value: getScalarType<Name, Schema> extends Value\n      ? never extends Value\n        ? never\n        : (Value & getScalarType<Name, Schema>) | null\n      : getScalarType<Name, Schema> | null\n  ): Value | null;\n  scalar<const Name extends string, Value>(\n    name: Name,\n    value: getScalarType<Name, Schema> extends Value\n      ? never extends Value\n        ? never\n        : (Value & getScalarType<Name, Schema>) | undefined\n      : getScalarType<Name, Schema> | undefined\n  ): Value | undefined;\n  scalar<const Name extends string, Value>(\n    name: Name,\n    value: getScalarType<Name, Schema> extends Value\n      ? never extends Value\n        ? never\n        : (Value & getScalarType<Name, Schema>) | null | undefined\n      : getScalarType<Name, Schema> | null | undefined\n  ): Value | null | undefined;\n  scalar<const Name extends string>(\n    name: Name,\n    value: getScalarType<Name, Schema> | undefined\n  ): getScalarType<Name, Schema>;\n\n  /** Function to replace a GraphQL document with a persisted document.\n   *\n   * @typeParam Document - The document type of {@link TadaDocumentNode}.\n   * @param id - A document ID that replaces the document for the API.\n   * @returns A {@link TadaPersistedDocumentNode}.\n   *\n   * @remarks\n   * This function may be used to replace a GraphQL document with a\n   * stand-in, persisted document.\n   *\n   * The returned document’s value won’t contain any of the document’s\n   * definitions, but its type will be equivalent to the `Document` that’s\n   * been passed as a generic.\n   *\n   * As long as the query (type parameter of `Document`) is only referenced\n   * as a type in your code, it will be omitted from your output build by\n   * your bundler and the resulting GraphQL document’s ID will replace your\n   * document entirely.\n   *\n   * @example\n   * ```\n   * import { graphql } from 'gql.tada';\n   *\n   * const query = graphql(`query MyQuery { __typename }`);\n   * const persisted = graphql.persisted<typeof query>('MyQuery');\n   * ```\n   */\n  persisted<Document extends DocumentNodeLike = never>(\n    documentId: string,\n    document?: Document\n  ): Document extends DocumentDecoration<infer Result, infer Variables>\n    ? TadaPersistedDocumentNode<Result, Variables>\n    : never;\n}\n\ntype schemaOfSetup<Setup extends AbstractSetupSchema> = addIntrospectionScalars<\n  mapIntrospection<matchOr<IntrospectionLikeInput, Setup['introspection'], never>>,\n  matchOr<ScalarsLike, Setup['scalars'], {}>\n>;\n\ntype configOfSetup<Setup extends AbstractSetupSchema> = {\n  isMaskingDisabled: Setup['disableMasking'] extends true ? true : false;\n};\n\n/** Setup function to create a typed `graphql` document function with.\n *\n * @remarks\n * `initGraphQLTada` accepts an {@link AbstractSetupSchema} configuration object as a generic\n * and returns a `graphql` function that may be used to create documents typed using your\n * GraphQL schema.\n *\n * You should use and re-export the resulting function named as `graphql` or `gql` for your\n * editor and the TypeScript language server to recognize your GraphQL documents correctly.\n *\n * @example\n * ```\n * import { initGraphQLTada } from 'gql.tada';\n * import type { myIntrospection } from './myIntrospection';\n *\n * export const graphql = initGraphQLTada<{\n *   introspection: typeof myIntrospection;\n *   scalars: {\n *     DateTime: string;\n *     Json: any;\n *   };\n * }>();\n *\n * const query = graphql(`{ __typename }`);\n * ```\n */\nfunction initGraphQLTada<const Setup extends AbstractSetupSchema>() {\n  type Schema = schemaOfSetup<Setup>;\n  type Config = configOfSetup<Setup>;\n\n  function graphql(input: string, fragments?: readonly TadaDocumentNode[]): any {\n    const definitions = _parse(input).definitions as writable<DefinitionNode>[];\n    const seen = new Set<unknown>();\n    for (const document of fragments || []) {\n      for (const definition of document.definitions) {\n        if (definition.kind === Kind.FRAGMENT_DEFINITION && !seen.has(definition)) {\n          definitions.push(definition);\n          seen.add(definition);\n        }\n      }\n    }\n\n    if (definitions[0].kind === Kind.FRAGMENT_DEFINITION && definitions[0].directives) {\n      definitions[0].directives = definitions[0].directives.filter(\n        (directive) => directive.name.value !== '_unmask'\n      );\n    }\n\n    return { kind: Kind.DOCUMENT, definitions };\n  }\n\n  graphql.scalar = function scalar(_schema: Schema, value: any) {\n    return value;\n  };\n\n  graphql.persisted = function persisted(\n    documentId: string,\n    document?: TadaDocumentNode\n  ): TadaPersistedDocumentNode {\n    return {\n      kind: Kind.DOCUMENT,\n      definitions: document ? document.definitions : [],\n      documentId,\n    };\n  };\n\n  return graphql as GraphQLTadaAPI<Schema, Config>;\n}\n\n/** Alias to a GraphQL parse function returning an exact document type.\n *\n * @param input - A string of a GraphQL document\n * @returns A parsed {@link DocumentNode}.\n *\n * @remarks\n * This function accepts a GraphQL document string and parses it, just like\n * GraphQL’s `parse` function. However, its return type will be the exact\n * structure of the AST parsed in types.\n */\nfunction parse<const In extends string>(input: In): parseDocument<In> {\n  return _parse(input) as any;\n}\n\nexport type getDocumentNode<\n  Document extends DocumentNodeLike,\n  Introspection extends SchemaLike,\n  Fragments extends { [name: string]: any } = {},\n  isMaskingDisabled = false,\n> = getDocumentType<Document, Introspection, Fragments> extends never\n  ? never\n  : TadaDocumentNode<\n      getDocumentType<Document, Introspection, Fragments>,\n      getVariablesType<Document, Introspection>,\n      decorateFragmentDef<Document, isMaskingDisabled>\n    >;\n\n/** A GraphQL `DocumentNode` with attached types for results and variables.\n *\n * @remarks\n * This is a GraphQL {@link DocumentNode} with attached types for results and variables.\n * This is used by GraphQL clients to infer the types of results and variables and provide\n * type-safety in GraphQL documents.\n *\n * You can create typed GraphQL documents using the {@link graphql} function.\n *\n * `Result` is the type of GraphQL results, as returned by GraphQL APIs for a given query.\n * `Variables` is the type of variables, as accepted by GraphQL APIs for a given query.\n *\n * @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information.\n */\ninterface TadaDocumentNode<\n  Result = { [key: string]: any },\n  Variables = { [key: string]: any },\n  Decoration = void,\n> extends DocumentNode,\n    DocumentDecoration<Result, Variables>,\n    DefinitionDecoration<Decoration> {}\n\n/** A GraphQL persisted document with attached types for results and variables.\n *\n * @remarks\n * This type still matches a GraphQL {@link DocumentNode}, but doesn’t contain\n * any definitions. At runtime, this means that this document is empty.\n *\n * Instead of its definitions, it carries an `id` property that is typically\n * used to uniquely identify the document to your GraphQL API, without disclosing\n * the shape of the query or schema transparently.\n */\ninterface TadaPersistedDocumentNode<\n  Result = { [key: string]: any },\n  Variables = { [key: string]: any },\n> extends DocumentNode,\n    DocumentDecoration<Result, Variables> {\n  definitions: readonly DefinitionNode[];\n  documentId: string;\n}\n\n/** A utility type returning the `Result` type of typed GraphQL documents.\n *\n * @remarks\n * This accepts a {@link TadaDocumentNode} and returns the attached `Result` type\n * of GraphQL documents.\n */\ntype ResultOf<Document> = Document extends DocumentDecoration<infer Result, any> ? Result : never;\n\n/** A utility type returning the `Variables` type of typed GraphQL documents.\n *\n * @remarks\n * This accepts a {@link TadaDocumentNode} and returns the attached `Variables` type\n * of GraphQL documents.\n */\ntype VariablesOf<Document> = Document extends DocumentDecoration<any, infer Variables>\n  ? Variables\n  : never;\n\n/** Creates a fragment mask for a given fragment document.\n *\n * @remarks\n * When {@link graphql} is used to create a fragment and is spread into another\n * fragment or query, their result types will only contain a “reference” to the\n * fragment. This encourages isolation and is known as “fragment masking.”\n *\n * While {@link readFragment} is used to unmask these fragment masks, this utility\n * creates a fragment mask, so you can accept the masked data in the part of your\n * codebase that defines a fragment.\n *\n * @example\n * ```\n * import { FragmentOf, graphql, readFragment } from 'gql.tada';\n *\n * const bookFragment = graphql(`\n *   fragment BookComponent on Book {\n *     id\n *     title\n *   }\n * `);\n *\n * // May be called with any GraphQL data that contains a spread of `bookFragment`\n * const getBook = (data: FragmentOf<typeof bookFragment>) => {\n *   // Unmasks the fragment and casts to the result type of `bookFragment`\n *   const book = readFragment(bookFragment, data);\n * };\n * ```\n *\n * @see {@link readFragment} for how to read from fragment masks.\n */\ntype FragmentOf<Document extends FragmentShape> = makeFragmentRef<Document>;\n\ntype resultOrFragmentOf<Document extends FragmentShape> = FragmentOf<Document> | ResultOf<Document>;\n\ntype resultOfFragmentsRec<\n  Fragments extends readonly any[],\n  Result = {},\n> = Fragments extends readonly [infer Fragment, ...infer Rest]\n  ? resultOfFragmentsRec<Rest, ResultOf<Fragment> & Result>\n  : Result;\n\ntype fragmentRefsOfFragmentsRec<\n  Fragments extends readonly any[],\n  FragmentRefs = {},\n> = Fragments extends readonly [infer Fragment, ...infer Rest]\n  ? fragmentRefsOfFragmentsRec<Rest, makeFragmentRef<Fragment> & FragmentRefs>\n  : obj<FragmentRefs>;\n\n/** Unmasks a fragment mask for a given fragment document and data.\n *\n * @param _document - A GraphQL document of a fragment, created using {@link graphql}.\n * @param fragment - A mask of the fragment, which can be wrapped in arrays, or nullable.\n * @returns The unmasked data of the fragment.\n *\n * @remarks\n * When {@link graphql} is used to create a fragment and is spread into another\n * fragment or query, their result types will only contain a “reference” to the\n * fragment. This encourages isolation and is known as “fragment masking.”\n *\n * This means that you must use {@link readFragment} to unmask these fragment masks\n * and get to the data. This encourages isolation and only using the data you define\n * a part of your codebase to require.\n *\n * @example\n * ```\n * import { FragmentOf, graphql, readFragment } from 'gql.tada';\n *\n * const bookFragment = graphql(`\n *   fragment BookComponent on Book {\n *     id\n *     title\n *   }\n * `);\n *\n * const getBook = (data: FragmentOf<typeof bookFragment> | null) => {\n *   // Unmasks the fragment and casts to the result type of `bookFragment`\n *   // This is intersected with `| null` in this case, due to the input type.\n *   const book = readFragment(bookFragment, data);\n * };\n *\n * const bookQuery = graphql(`\n *   query Book ($id: ID!) {\n *     book(id: $id) {\n *       id\n *       ...BookComponent\n *     }\n *   }\n * `, [bookFragment]);\n *\n * const getQuery = (data: ResultOf<typeof bookQuery>) => {\n *   getBook(data?.book);\n * };\n * ```\n *\n * @see {@link readFragment} for how to read from fragment masks.\n */\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: resultOrFragmentOf<Document>\n): ResultOf<Document>;\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: resultOrFragmentOf<Document> | null\n): ResultOf<Document> | null;\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: resultOrFragmentOf<Document> | undefined\n): ResultOf<Document> | undefined;\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: resultOrFragmentOf<Document> | null | undefined\n): ResultOf<Document> | null | undefined;\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: readonly resultOrFragmentOf<Document>[]\n): readonly ResultOf<Document>[];\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: readonly (resultOrFragmentOf<Document> | null)[]\n): readonly (ResultOf<Document> | null)[];\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: readonly (resultOrFragmentOf<Document> | undefined)[]\n): readonly (ResultOf<Document> | undefined)[];\nfunction readFragment<const Document extends FragmentShape = never>(\n  fragment: readonly (resultOrFragmentOf<Document> | null | undefined)[]\n): readonly (ResultOf<Document> | null | undefined)[];\nfunction readFragment<const Document extends FragmentShape = never>(\n  _document: Document,\n  fragment: resultOrFragmentOf<Document>\n): ResultOf<Document>;\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: resultOrFragmentOf<Document> | null\n): ResultOf<Document> | null;\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: resultOrFragmentOf<Document> | undefined\n): ResultOf<Document> | undefined;\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: resultOrFragmentOf<Document> | null | undefined\n): ResultOf<Document> | null | undefined;\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: readonly resultOrFragmentOf<Document>[]\n): readonly ResultOf<Document>[];\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: readonly (resultOrFragmentOf<Document> | null)[]\n): readonly (ResultOf<Document> | null)[];\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: readonly (resultOrFragmentOf<Document> | undefined)[]\n): readonly (ResultOf<Document> | undefined)[];\nfunction readFragment<const Document extends FragmentShape>(\n  _document: Document,\n  fragment: readonly (resultOrFragmentOf<Document> | null | undefined)[]\n): readonly (ResultOf<Document> | null | undefined)[];\nfunction readFragment(...args: [unknown] | [unknown, unknown]) {\n  return args.length === 2 ? args[1] : args[0];\n}\n\n/** For testing, masks fragment data for given data and fragments.\n *\n * @param _fragments - A list of GraphQL documents of fragments, created using {@link graphql}.\n * @param data - The combined result data of the fragments, which can be wrapped in arrays.\n * @returns The masked data of the fragments.\n *\n * @remarks\n * When creating test data, you may define data for fragments that’s unmasked, making it\n * unusable in parent fragments or queries that require masked data.\n *\n * This means that you may have to use {@link maskFragments} to mask your data first\n * for TypeScript to not report an error.\n *\n * @example\n * ```\n * import { FragmentOf, ResultOf, graphql, maskFragments } from 'gql.tada';\n *\n * const bookFragment = graphql(`\n *   fragment BookComponent on Book {\n *     id\n *     title\n *   }\n * `);\n *\n * const data = maskFragments([bookFragment], { id: 'id', title: 'book' });\n * ```\n *\n * @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)\n */\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: resultOfFragmentsRec<Fragments>\n): fragmentRefsOfFragmentsRec<Fragments>;\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: resultOfFragmentsRec<Fragments> | null\n): fragmentRefsOfFragmentsRec<Fragments> | null;\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: resultOfFragmentsRec<Fragments> | undefined\n): fragmentRefsOfFragmentsRec<Fragments> | undefined;\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: resultOfFragmentsRec<Fragments> | null | undefined\n): fragmentRefsOfFragmentsRec<Fragments> | null | undefined;\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: readonly resultOfFragmentsRec<Fragments>[]\n): readonly fragmentRefsOfFragmentsRec<Fragments>[];\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: readonly (resultOfFragmentsRec<Fragments> | null)[]\n): readonly (fragmentRefsOfFragmentsRec<Fragments> | null)[];\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: readonly (resultOfFragmentsRec<Fragments> | undefined)[]\n): readonly (fragmentRefsOfFragmentsRec<Fragments> | undefined)[];\nfunction maskFragments<const Fragments extends readonly FragmentShape[]>(\n  _fragments: Fragments,\n  fragment: readonly (resultOfFragmentsRec<Fragments> | null | undefined)[]\n): readonly (fragmentRefsOfFragmentsRec<Fragments> | null | undefined)[];\nfunction maskFragments(_fragments: unknown, data: unknown) {\n  return data;\n}\n\n/** For testing, converts document data without fragment refs to their result type.\n *\n * @param _document - A GraphQL document, created using {@link graphql}.\n * @param data - The result data of the GraphQL document with optional fragment refs.\n * @returns The masked result data of the document.\n *\n * @remarks\n * When creating test data, you may define data for documents that’s unmasked, but\n * need to cast the data to match the result type of your document.\n *\n * This means that you may have to use {@link unsafe_readResult} to cast\n * them to the result type, instead of doing `as any as ResultOf<typeof document>`.\n *\n * This function is inherently unsafe, since it doesn't check that your document\n * actually contains the masked fragment data!\n *\n * @example\n * ```\n * import { FragmentOf, ResultOf, graphql, unsafe_readResult } from 'gql.tada';\n *\n * const bookFragment = graphql(`\n *   fragment BookComponent on Book {\n *     id\n *     title\n *   }\n * `);\n *\n * const query = graphql(`\n *   query {\n *     book {\n *       ...BookComponent\n *     }\n *   }\n * `, [bookFragment]);\n *\n * const data = unsafe_readResult(query, { book: { id: 'id', title: 'book' } });\n * ```\n *\n * @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)\n */\nfunction unsafe_readResult<\n  const Document extends DocumentDecoration<any, any>,\n  const Data extends omitFragmentRefsRec<ResultOf<Document>>,\n>(_document: Document, data: Data): ResultOf<Document> {\n  return data as any;\n}\n\nconst graphql: GraphQLTadaAPI<\n  schemaOfSetup<setupSchema>,\n  configOfSetup<setupSchema>\n> = initGraphQLTada();\n\nexport { parse, graphql, readFragment, maskFragments, unsafe_readResult, initGraphQLTada };\n\nexport type {\n  setupCache,\n  setupSchema,\n  parseDocument,\n  AbstractSetupSchema,\n  AbstractSetupCache,\n  GraphQLTadaAPI,\n  TadaDocumentNode,\n  TadaPersistedDocumentNode,\n  ResultOf,\n  VariablesOf,\n  FragmentOf,\n};\n"],"names":["initGraphQLTada","graphql","input","fragments","definitions","_parse","seen","Set","document","definition","kind","Kind","FRAGMENT_DEFINITION","has","push","add","directives","filter","directive","name","value","DOCUMENT","scalar","_schema","persisted","documentId","parse","readFragment","args","length","maskFragments","_fragments","data","unsafe_readResult","_document"],"mappings":";;AA+RA,SAASA;EAIP,SAASC,QAAQC,GAAeC;IAC9B,IAAMC,IAAcC,EAAOH,GAAOE;IAClC,IAAME,IAAO,IAAIC;IACjB,KAAK,IAAMC,KAAYL,KAAa;MAClC,KAAK,IAAMM,KAAcD,EAASJ;QAChC,IAAIK,EAAWC,SAASC,EAAKC,wBAAwBN,EAAKO,IAAIJ,IAAa;UACzEL,EAAYU,KAAKL;UACjBH,EAAKS,IAAIN;AACX;;;IAIJ,IAAIL,EAAY,GAAGM,SAASC,EAAKC,uBAAuBR,EAAY,GAAGY;MACrEZ,EAAY,GAAGY,aAAaZ,EAAY,GAAGY,WAAWC,QACnDC,KAAuC,cAAzBA,EAAUC,KAAKC;;IAIlC,OAAO;MAAEV,MAAMC,EAAKU;MAAUjB;;AAChC;EAEAH,QAAQqB,SAAS,SAASA,OAAOC,GAAiBH;IAChD,OAAOA;;EAGTnB,QAAQuB,YAAY,SAASA,UAC3BC,GACAjB;IAEA,OAAO;MACLE,MAAMC,EAAKU;MACXjB,aAAaI,IAAWA,EAASJ,cAAc;MAC/CqB;;;EAIJ,OAAOxB;AACT;;AAYA,SAASyB,MAA+BxB;EACtC,OAAOG,EAAOH;AAChB;;AAmOA,SAASyB,gBAAgBC;EACvB,OAAuB,MAAhBA,EAAKC,SAAeD,EAAK,KAAKA,EAAK;AAC5C;;AA+DA,SAASE,cAAcC,GAAqBC;EAC1C,OAAOA;AACT;;AA0CA,SAASC,kBAGPC,GAAqBF;EACrB,OAAOA;AACT;;AAEA,IAAM/B,IAGFD;;"}