Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created June 23, 2018 11:07
Show Gist options
  • Save zapkub/2eba8ab7d7b9468a5654426a16ba1ef6 to your computer and use it in GitHub Desktop.
Save zapkub/2eba8ab7d7b9468a5654426a16ba1ef6 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment