Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make isFragmentReady function work with enabled noUncheckedIndexedAccess tsc setting #9385

Merged
merged 8 commits into from
May 12, 2023
5 changes: 5 additions & 0 deletions .changeset/four-buckets-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/client-preset': patch
---

Improve isFragmentReady utility function to work with noUncheckedIndexedAccess TSC setting
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations-urql/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion dev-test/gql-tag-operations/graphql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export function isFragmentReady<TQuery, TFrag>(

const fragName = fragmentNode.__meta__?.fragmentName;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/persisted-documents/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
3 changes: 2 additions & 1 deletion examples/react/apollo-client-defer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true
"noEmit": true,
"noUncheckedIndexedAccess": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/react/apollo-client/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/react/http-executor/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/react/nextjs-swr/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export function isFragmentReady<TQuery, TFrag>(

const fragName = fragmentNode.__meta__?.fragmentName;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/react/urql/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export function isFragmentReady<TQuery, TFrag>(

const fragName = fragmentNode.__meta__?.fragmentName;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/typescript-esm/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export function isFragmentReady<TQuery, TFrag>(

const fragName = fragmentNode.__meta__?.fragmentName;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vite/vite-react-cts/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vite/vite-react-mts/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vite/vite-react-ts/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vue/apollo-composable/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vue/urql/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/vue/villus/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
2 changes: 1 addition & 1 deletion examples/yoga-tests/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
4 changes: 2 additions & 2 deletions packages/presets/client/src/fragment-masking-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function isFragmentReady<TQuery, TFrag>(

const fragName = fragmentNode.__meta__?.fragmentName;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
`;
Expand All @@ -105,7 +105,7 @@ export function isFragmentReady<TQuery, TFrag>(
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/presets/client/tests/client-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export * from "./gql";`);
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
const fields = (fragName && deferredFields[fragName]) || [];
return fields.length > 0 && fields.every(field => data && field in data);
}
"
Expand Down