Skip to content

Commit

Permalink
feat: modify @include/skip field as nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
xufeixiang committed Jun 4, 2024
1 parent 9a360a7 commit af842ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/engine/build/operations_graphql_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (i *QueryDocumentItem) resolveSelectionSet(datasourceQuote string, selectio
var (
itemName string
itemPath []string
itemNonNull bool
itemSchemaRef *openapi3.SchemaRef
itemCustomizedDirectiveName string
)
Expand Down Expand Up @@ -221,9 +222,7 @@ func (i *QueryDocumentItem) resolveSelectionSet(datasourceQuote string, selectio
}
return
}, path...)
if fieldDefinition.Type.NonNull {
selectionSchema.Required = append(selectionSchema.Required, itemName)
}
itemNonNull = fieldDefinition.Type.NonNull
i.resolveSelectionArguments(field.Name, field.Arguments, fieldDefinition, path...)
} else {
var itemError error
Expand All @@ -241,7 +240,11 @@ func (i *QueryDocumentItem) resolveSelectionSet(datasourceQuote string, selectio
}

selectionSchema.Properties[itemName] = itemSchemaRef
originNullable := itemSchemaRef.Value.Nullable
i.resolveSelectionDirectives(field.Directives, itemPath, itemSchemaRef, itemCustomizedDirectiveName)
if itemNonNull && !(!originNullable && itemSchemaRef.Value.Nullable) {
selectionSchema.Required = append(selectionSchema.Required, itemName)
}
}
}
return
Expand Down
1 change: 1 addition & 0 deletions pkg/engine/directives/selection_include.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *include) Resolve(resolver *SelectionResolver) (err error) {
return
}

resolver.Schema.Value.Nullable = true
if argIfFound {
if err = s.addVariablesSchema(resolver, argIfValue, boolSchema); err != nil {
return
Expand Down

0 comments on commit af842ae

Please sign in to comment.