Skip to content

Commit

Permalink
required check accept fragmentspread
Browse files Browse the repository at this point in the history
  • Loading branch information
joleeee committed Jan 13, 2025
1 parent d7b30f0 commit 89b357a
Showing 1 changed file with 18 additions and 10 deletions.
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

0 comments on commit 89b357a

Please sign in to comment.