All files / src graphql.tsx

100% Statements 10/10
100% Branches 6/6
100% Functions 1/1
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32    27x     27x 27x 27x   27x               217x   145x   19x   6x         119x      
import * as React from 'react';
import { DocumentNode } from 'graphql';
import { parser, DocumentType } from './parser';
import { OperationOption, DataProps, MutateProps } from './types';
 
import { query } from './query-hoc';
import { mutation } from './mutation-hoc';
import { subscribe } from './subscription-hoc';
 
export function graphql<
  TProps extends TGraphQLVariables | {} = {},
  TData = {},
  TGraphQLVariables = {},
  TChildProps = Partial<DataProps<TData, TGraphQLVariables>> &
    Partial<MutateProps<TData, TGraphQLVariables>>
>(
  document: DocumentNode,
  operationOptions: OperationOption<TProps, TData, TGraphQLVariables, TChildProps> = {},
) {
  switch (parser(document).type) {
    case DocumentType.Mutation:
      return mutation(document, operationOptions);
    case DocumentType.Subscription:
      return subscribe(document, operationOptions);
    // case DocumentType.Fragment:
    //   throw new Error('fragments cannont currently be used on their own');
    case DocumentType.Query:
    default:
      return query(document, operationOptions);
  }
}