Register fragment

This commit is contained in:
Kat Huang 2024-01-08 22:31:08 -07:00
parent fcdce8706f
commit 5204599a08
4 changed files with 29 additions and 14 deletions

View File

@ -7,6 +7,8 @@ import {
from,
} from "@apollo/client";
import { API_URI } from "@env";
import { SHOT_FEATURES_FRAGMENT } from "./fragment/shot";
import { createFragmentRegistry } from "@apollo/client/cache";
type Props = {
children: ReactNode;
@ -16,10 +18,13 @@ const ClientProvider: React.FC<Props> = ({ children }) => {
const httpLink = new HttpLink({
uri: API_URI,
});
const cache = new InMemoryCache({
fragments: createFragmentRegistry(SHOT_FEATURES_FRAGMENT),
});
const client = new ApolloClient({
link: from([httpLink]),
cache: new InMemoryCache(),
cache: cache,
});
return <ApolloProvider client={client}>{children}</ApolloProvider>;

View File

@ -1,10 +0,0 @@
import { gql } from "@apollo/client";
const SHOT_FEATURES_FRAGMENT = gql`
fragment ShotFeatures on ShotFeaturesGQL {
cueObjectAngle @include(if: $includeCueObjectAngle)
cueObjectDistance @include(if: $includeCueObjectDistance)
}
`;
export default SHOT_FEATURES_FRAGMENT;

13
graphql/fragment/shot.ts Normal file
View File

@ -0,0 +1,13 @@
import { gql } from "@apollo/client";
export const SHOT_FEATURES_FRAGMENT = gql`
fragment ShotFeatures on ShotFeaturesGQL {
cueObjectDistance @include(if: $includeCueObjectDistance)
targetPocketDistance @include(if: $includeTargetPocketDistance)
cueObjectAngle @include(if: $includeCueObjectAngle)
cueBallSpeed @include(if: $includeCueBallSpeed)
intendedPocket @include(if: $includeIntendedPocket)
shotDirection @include(if: $includeShotDirection)
didMake @include(if: $includeDidMake)
}
`;

View File

@ -1,15 +1,22 @@
import { gql } from "@apollo/client";
import SHOT_FEATURES_FRAGMENT from "./fragment/shot-features";
export const GET_SHOTS = gql`
${SHOT_FEATURES_FRAGMENT}
query GetShots(
$includeCueObjectAngle: Boolean! = false
$includeCueObjectDistance: Boolean! = false
$includeTargetPocketDistance: Boolean! = false
$includeCueObjectAngle: Boolean! = false
$includeCueBallSpeed: Boolean! = false
$includeIntendedPocket: Boolean! = false
$includeShotDirection: Boolean! = false
$includeDidMake: Boolean! = false
) {
getShots {
id
videoId
startFrame
endFrame
createdAt
updatedAt
features {
...ShotFeatures
}