Skip to content

Commit

Permalink
Merge branch 'master' into log-on-unsuccessful-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
al-yanna authored Dec 4, 2024
2 parents dea3ea9 + 6b2b430 commit 4668a49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/graphql-hive/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ def initialize(query_or_multiplex)
end

def on_enter_field(node, _parent, visitor)
@used_fields.add(visitor.parent_type_definition.graphql_name)
@used_fields.add(make_id(visitor.parent_type_definition.graphql_name, node.name))
parent_type = visitor.parent_type_definition
if parent_type&.respond_to?(:graphql_name) && parent_type.fields[node.name]
@used_fields.add(parent_type.graphql_name)
@used_fields.add(make_id(parent_type.graphql_name, node.name))
end
end

# Visitor also calls 'on_enter_argument' when visiting input object fields in arguments
Expand Down
23 changes: 23 additions & 0 deletions spec/graphql/graphql-hive/analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,27 @@
)
end
end

context "with an invalid field" do
let(:query_string) do
<<~GQL
query getGatewayProjects {
projectsByManyTypes(type: [STITCHING]),
nonExistentField {
subField
}
}
GQL
end

it "collects all valid fields and excludes invalid fields" do
expect(used_fields).to contain_exactly(
"Query",
"Query.projectsByManyTypes",
"ProjectType",
"Query.projectsByManyTypes.type",
"ProjectType.STITCHING"
)
end
end
end

0 comments on commit 4668a49

Please sign in to comment.