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 6, 2024
2 parents 0ef7809 + 980ea7d commit e230377
Showing 1 changed file with 108 additions and 59 deletions.
167 changes: 108 additions & 59 deletions spec/graphql/graphql-hive/analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,75 @@
end

let(:schema) do
GraphQL::Schema.from_definition(%|
type Query {
project(selector: ProjectSelectorInput!): Project
projectsByType(type: ProjectType!): [Project!]!
projectsByManyTypes(type: [ProjectType!]!): [Project!]!
projects(filter: FilterInput): [Project!]!
}
GraphQL::Schema.from_definition(
<<~GQL
type Query {
project(selector: ProjectSelectorInput!): Project
projectsByType(type: ProjectType!): [Project!]!
projectsByManyTypes(type: [ProjectType!]!): [Project!]!
projects(filter: FilterInput): [Project!]!
searchResult(query: String!): SearchResult
}
type Mutation {
deleteProject(selector: ProjectSelectorInput!): DeleteProjectPayload!
}
type Mutation {
deleteProject(selector: ProjectSelectorInput!): DeleteProjectPayload!
}
input ProjectSelectorInput {
organization: ID!
project: ID!
}
input ProjectSelectorInput {
organization: ID!
project: ID!
}
input FilterInput {
type: ProjectType
pagination: PaginationInput
order: [ProjectOrderByInput!]
}
input FilterInput {
type: ProjectType
pagination: PaginationInput
order: [ProjectOrderByInput!]
}
input PaginationInput {
limit: Int
offset: Int
}
input PaginationInput {
limit: Int
offset: Int
}
input ProjectOrderByInput {
field: String!
direction: OrderDirection
}
input ProjectOrderByInput {
field: String!
direction: OrderDirection
}
enum OrderDirection {
ASC
DESC
}
enum OrderDirection {
ASC
DESC
}
type ProjectSelector {
organization: ID!
project: ID!
}
type ProjectSelector {
organization: ID!
project: ID!
}
type DeleteProjectPayload {
selector: ProjectSelector!
deletedProject: Project!
}
type DeleteProjectPayload {
selector: ProjectSelector!
deletedProject: Project!
}
type Project {
id: ID!
cleanId: ID!
name: String!
type: ProjectType!
buildUrl: String
validationUrl: String
}
type Project {
id: ID!
cleanId: ID!
name: String!
type: ProjectType!
buildUrl: String
validationUrl: String
}
enum ProjectType {
FEDERATION
STITCHING
SINGLE
CUSTOM
}
|)
enum ProjectType {
FEDERATION
STITCHING
SINGLE
CUSTOM
}
union SearchResult = Project | ProjectSelector
GQL
)
end

let(:query_string) do
Expand Down Expand Up @@ -350,11 +355,51 @@
end
end

context "with a query containing a union type" do
let(:query_string) do
<<~GQL
query searchProjects {
searchResult(query: $query) {
__typename
... on Project {
id
}
... on ProjectSelector {
organization
}
}
}
GQL
end

it "collects all valid fields from union types" do
expect(used_fields).to contain_exactly(
"Query",
"Query.searchResult",
"Query.searchResult.query",
"SearchResult",
"SearchResult.__typename",
"Project",
"Project.id",
"ProjectSelector",
"ProjectSelector.organization",
"String"
)
end
end

context "with an invalid field" do
let(:query_string) do
<<~GQL
query getGatewayProjects {
projectsByManyTypes(type: [STITCHING]),
searchResult(query: $query) {
nonExistentField {
subField
}
... on Project {
id
}
}
nonExistentField {
subField
}
Expand All @@ -365,10 +410,14 @@
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"
"Query.searchResult",
"Query.searchResult.query",
"SearchResult",
"SearchResult.nonExistentField",
"Project",
"Project.id",
"Query.nonExistentField",
"String"
)
end
end
Expand Down

0 comments on commit e230377

Please sign in to comment.