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

required check accept fragmentspread #1411

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions packages/houdini/src/codegen/validators/typeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,24 @@ export default async function typeCheck(config: Config, docs: Document[]): Promi
}

function validateRequiredDirective(config: Config, filepath: string) {
function isClientNullable(node: graphql.FieldNode, ignoreCurrent: boolean): boolean {
function isClientNullable(node: graphql.FieldNode | graphql.FragmentSpreadNode, ignoreCurrent: boolean): boolean {
const hasRequiredDirective = node.directives?.some(
({ name }) => name.value === config.requiredDirective
)
return (
(!ignoreCurrent && hasRequiredDirective) ||
node.selectionSet?.selections.some(
(node) => node.kind == 'Field' && isClientNullable(node, false)
) == true
)
) ?? false

if (!ignoreCurrent && hasRequiredDirective) {
return true;
}

if (node.kind === 'Field') {
return (
(!ignoreCurrent && hasRequiredDirective) || node.selectionSet?.selections.some(
(node) => node.kind == 'Field' || node.kind == 'FragmentSpread' && isClientNullable(node, false)
) == true
)
}

return false;
}

return function (ctx: graphql.ValidationContext): graphql.ASTVisitor {
Expand Down Expand Up @@ -530,7 +538,7 @@ const validateLists = ({
ctx.reportError(
new graphql.GraphQLError(
'@connection was renamed to @list. Please change your components. ' +
'If you were using `cache.connection` in your components, you will need to update that to `cache.list` too.'
'If you were using `cache.connection` in your components, you will need to update that to `cache.list` too.'
)
)
return
Expand Down Expand Up @@ -725,7 +733,7 @@ function validateFragmentArguments(
ctx.reportError(
new graphql.GraphQLError(
`The following arguments are missing from the "${fragmentName}" fragment: ` +
JSON.stringify(missing)
JSON.stringify(missing)
)
)
return
Expand Down