{"version":3,"file":"daffodil-core-graphql.mjs","sources":["../../../libs/core/graphql/src/fragments/build-fragment-name-spread.ts","../../../libs/core/graphql/src/fragments/build-fragment-definition.ts","../../../libs/core/graphql/src/apollo/queued-apollo/queued-apollo.service.ts","../../../libs/core/graphql/src/apollo/request-handler.provider.ts","../../../libs/core/graphql/src/apollo/header/get.ts","../../../libs/core/graphql/src/apollo/header/provider.ts","../../../libs/core/graphql/src/daffodil-core-graphql.ts"],"sourcesContent":["import {\n  DocumentNode,\n  FragmentDefinitionNode,\n} from 'graphql';\n\nimport { unique } from '@daffodil/core';\n\nexport const getFragmentNames = (fragment: DocumentNode) =>\n  fragment.definitions.filter(def =>\n    def.kind === 'FragmentDefinition',\n  ).map(def =>\n    (<FragmentDefinitionNode>def).name.value,\n  );\n\n/**\n * Builds a list of the first fragment name present inside the specified GraphQL document nodes.\n * Returns an empty array if no fragments have been defined or if null is passed.\n *\n * @param fragments The created fragments.\n */\nconst daffGetFragmentNames = (...fragments: DocumentNode[]): string[] =>\n  fragments.reduce((acc, fragment) => {\n    const names = getFragmentNames(fragment);\n    if (names[0]) {\n      acc.push(names[0]);\n    }\n    return acc;\n  }, []);\n\n/**\n * Builds a string of fragment names that can be interpolated into a GraphQL query.\n * Each name is separated by a newline character: '\\n'.\n * If an empty array is passed, an empty string is returned.\n * Only the first fragment name from each passed fragment is returned.\n *\n * @param fragments A list of GraphQL documents that contain fragments.\n */\nexport const daffBuildFragmentNameSpread = (...fragments: DocumentNode[]): string =>\n  unique(daffGetFragmentNames(...fragments)).reduce((acc, name) => acc.concat(`...${name}\\n`), '');\n","import { DocumentNode } from 'graphql';\n\n/**\n * Builds a string of fragment definitions that can be interpolated into a GraphQL query.\n * Each definition is separated by a newline character: '\\n'.\n *\n * @param documents A list of GraphQL documents that should only contain fragments.\n */\nexport const daffBuildFragmentDefinition = (...documents: DocumentNode[]): string =>\n  documents.reduce((acc, fragment) => acc.concat(`${fragment.loc.source.body}\\n`), '');\n","import { Injectable } from '@angular/core';\nimport { Apollo } from 'apollo-angular';\nimport {\n  Observable,\n  Subscriber,\n  Subscription,\n} from 'rxjs';\n\n/**\n * A service that will queue mutate calls to Apollo.\n * It will not send subsequent mutate requests until the previous one has been completed.\n * This is useful for avoiding race conditions on the backend.\n * This should be used alongside Apollo.\n */\n@Injectable({\n  providedIn: 'root',\n})\nexport class DaffQueuedApollo {\n  queue: (() => void)[] = [];\n\n  constructor(\n    private apollo: Apollo,\n  ) {}\n\n  /**\n   * Queue up a mutate request.\n   * The request will not actually be queued until the returned observable is subscribed.\n   * If the queue is empty, the request will be sent when it enters the queue.\n   * Otherwise, it will be sent when it reaches the front of the queue.\n   * The observable will complete after it emits once.\n   *\n   * @param options Mutation options.\n   */\n  mutate<T, V = Record<string, any>>(options: Apollo.MutateOptions<T, V>): Observable<Apollo.MutateResult<T>> {\n    return new Observable(subscriber => this.addRequestToQueue(subscriber, this.apollo.mutate(options)));\n  }\n\n  private addRequestToQueue(subscriber: Subscriber<any>, request: Observable<any>): void {\n    this.queue.push(() => {\n      const sub = request.subscribe({\n        next: response => {\n          // emit the outer observable\n          subscriber.next(response);\n          subscriber.complete();\n\n          this.finishRequestSubscription(sub);\n        },\n        error: error => {\n          subscriber.error(error);\n          this.finishRequestSubscription(sub);\n        },\n        complete: () => {\n          subscriber.complete();\n          this.finishRequestSubscription(sub);\n        },\n      });\n    });\n\n    // start the queue if previously empty\n    if (this.queue.length === 1) {\n      this.queue[0]();\n    }\n  }\n\n  private finishRequestSubscription(requestSubscription: Subscription): void {\n    requestSubscription.unsubscribe();\n\n    // process queue\n    this.queue.shift();\n    this.queue[0]?.();\n  }\n}\n","import { ApolloLink } from '@apollo/client';\n\nimport { createMultiInjectionToken } from '@daffodil/core';\n\nexport const {\n  /**\n   * Apollo request handlers. Allow custom logic to be injected into the apollo link chain.\n   */\n  token: DAFF_APOLLO_REQUEST_HANDLERS,\n  /**\n   * Provider for {@link DAFF_APOLLO_REQUEST_HANDLERS}.\n   */\n  provider: provideDaffApolloRequestHandlers,\n  /**\n   * Factory provider for {@link DAFF_APOLLO_REQUEST_HANDLERS}.\n   */\n  factoryProvider: provideDaffApolloRequestHandlerFactories,\n} = createMultiInjectionToken<ApolloLink.RequestHandler>('DAFF_APOLLO_REQUEST_HANDLERS');\n","import { HttpHeaders } from '@angular/common/http';\nimport { ApolloLink } from '@apollo/client';\n\nexport function getApolloOperationHeaders(operation: ApolloLink.Operation): HttpHeaders {\n  return operation.getContext().headers || new HttpHeaders();\n}\n","import {\n  EnvironmentProviders,\n  inject,\n  Injector,\n  makeEnvironmentProviders,\n  runInInjectionContext,\n} from '@angular/core';\n\nimport { DaffApolloHeaderProvider } from './type';\nimport { provideDaffApolloRequestHandlerFactories } from '../request-handler.provider';\nimport { getApolloOperationHeaders } from './get';\n\n/**\n * Provider function for {@link DaffApolloHeaderProvider}s.\n */\nexport const provideDaffApolloHeaderProviders = (...providers: Array<DaffApolloHeaderProvider>): EnvironmentProviders =>\n  makeEnvironmentProviders([\n    provideDaffApolloRequestHandlerFactories(() => {\n      const injector = inject(Injector);\n      return (operation, forward) => {\n        operation.setContext({\n          headers: providers.reduce((acc, provider) => {\n            const headers = runInInjectionContext(injector, provider);\n            headers.keys().forEach((key) => {\n              const val = headers.getAll(key);\n              if (val) {\n                acc.append(key, val);\n              }\n            });\n            return acc;\n          }, getApolloOperationHeaders(operation)),\n        });\n        return forward(operation);\n      };\n    }),\n  ]);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAOO,MAAM,gBAAgB,GAAG,CAAC,QAAsB,KACrD,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,IAC7B,GAAG,CAAC,IAAI,KAAK,oBAAoB,CAClC,CAAC,GAAG,CAAC,GAAG,IACkB,GAAI,CAAC,IAAI,CAAC,KAAK,CACzC;AAEH;;;;;AAKG;AACH,MAAM,oBAAoB,GAAG,CAAC,GAAG,SAAyB,KACxD,SAAS,CAAC,M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