Skip to content

Commit

Permalink
[TT-5117] Expanded fielded and sdlmerge test suites.
Browse files Browse the repository at this point in the history
[changelog]
internal: Expanded fielded and sdlmerge test suites.
  • Loading branch information
David Stutt committed May 4, 2022
1 parent a68d94d commit de97afa
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ func TestRemoveDuplicateFieldlessValueTypes(t *testing.T) {
`)
})

t.Run("Identical same name enums are merged into a single input regardless of value order", func(t *testing.T) {
run(t, newRemoveDuplicateFieldlessValueTypesVisitor(), `
enum Pokemon {
BULBASAUR,
CHARMANDER,
SQUIRTLE,
}
enum Pokemon {
SQUIRTLE,
CHARMANDER,
BULBASAUR,
}
`, `
enum Pokemon {
BULBASAUR,
CHARMANDER,
SQUIRTLE,
}
`)
})

t.Run("Same name enums with different values return an error", func(t *testing.T) {
runAndExpectError(t, newRemoveDuplicateFieldlessValueTypesVisitor(), `
enum Pokemon {
Expand Down Expand Up @@ -276,6 +298,16 @@ func TestRemoveDuplicateFieldlessValueTypes(t *testing.T) {
`)
})

t.Run("Identical same name unions are merged into a single input regardless of value order", func(t *testing.T) {
run(t, newRemoveDuplicateFieldlessValueTypesVisitor(), `
union Types = Grass | Fire | Water
union Types = Water | Grass | Fire
`, `
union Types = Grass | Fire | Water
`)
})

t.Run("Same name unions with different values return an error", func(t *testing.T) {
runAndExpectError(t, newRemoveDuplicateFieldlessValueTypesVisitor(), `
union Types = Grass | Fire | Water
Expand Down
140 changes: 124 additions & 16 deletions pkg/federation/sdlmerge/sdlmerge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const (
scalar DateTime
scalar CustomScalar
type User @key(fields: "id") {
id: ID!
username: String!
Expand All @@ -148,9 +148,9 @@ const (

productSchema = `
enum Satisfaction {
UNHAPPY,
HAPPY,
NEUTRAL,
UNHAPPY,
}
scalar CustomScalar
Expand All @@ -165,31 +165,57 @@ const (
GROCERIES,
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
scalar BigInt
type Product @key(fields: "upc") {
type Product implements ProductInfo @key(fields: "upc") {
upc: String!
name: String!
price: Int!
worth: BigInt!
reputation: CustomScalar!
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
`
reviewSchema = `
scalar DateTime
type Review {
input ReviewInput {
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Review {
id: ID!
created: DateTime!
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Query {
getReview(id: ID!): Review
}
type Mutation {
createReview(input: ReviewInput): Review
updateReview(id: ID!, input: ReviewInput): Review
}
enum Department {
GROCERIES,
COSMETICS,
ELECTRONICS,
GROCERIES,
}
extend type User @key(fields: "id") {
Expand All @@ -204,7 +230,7 @@ const (
sales: BigInt!
}
union AlphaNumeric = Int | String | Float
union AlphaNumeric = Float | String | Int
enum Satisfaction {
HAPPY,
Expand All @@ -215,19 +241,48 @@ const (
extend type Subscription {
review: Review!
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
`

negativeTestingReviewSchema = `
scalar DateTime
type Review {
input ReviewInput {
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Review {
id: ID!
created: DateTime!
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Query {
getReview(id: ID!): Review
}
type Mutation {
createReview(input: ReviewInput): Review
updateReview(id: ID!, input: ReviewInput): Review
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
enum Department {
COSMETICS,
ELECTRONICS,
Expand Down Expand Up @@ -330,7 +385,7 @@ const (
onlinePaymentSchema = `
scalar DateTime
union AlphaNumeric = Int | String | Float
union AlphaNumeric = String | Float | Int
scalar BigInt
Expand Down Expand Up @@ -380,9 +435,15 @@ const (
type Query {
me: User
topProducts(first: Int = 5): [Product]
getReview(id: ID!): Review
likesCount(productID: ID!): Int!
likes(productID: ID!): [Like]!
}
type Mutation {
createReview(input: ReviewInput): Review
updateReview(id: ID!, input: ReviewInput): Review
}
type Subscription {
review: Review!
Expand Down Expand Up @@ -413,24 +474,41 @@ const (
ELECTRONICS,
GROCERIES,
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
scalar BigInt
type Product {
type Product implements ProductInfo {
upc: String!
name: String!
price: Int!
worth: BigInt!
reputation: CustomScalar!
departments: [Department!]!
averageSatisfaction: Satisfaction!
reviews: [Review]
sales: BigInt!
}
input ReviewInput {
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Review {
id: ID!
created: DateTime!
body: String!
author: User!
product: Product!
created: DateTime!
updated: DateTime!
inputType: AlphaNumeric!
}
Expand All @@ -455,16 +533,22 @@ const (
productAndReviewFederatedSchema = `
type Query {
topProducts(first: Int = 5): [Product]
getReview(id: ID!): Review
}
type Mutation {
createReview(input: ReviewInput): Review
updateReview(id: ID!, input: ReviewInput): Review
}
type Subscription {
review: Review!
}
enum Satisfaction {
UNHAPPY,
HAPPY,
NEUTRAL,
UNHAPPY,
}
scalar CustomScalar
Expand All @@ -475,25 +559,42 @@ const (
GROCERIES,
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
scalar BigInt
type Product {
type Product implements ProductInfo {
upc: String!
name: String!
price: Int!
worth: BigInt!
reputation: CustomScalar!
departments: [Department!]!
averageSatisfaction: Satisfaction!
reviews: [Review]
sales: BigInt!
}
scalar DateTime
input ReviewInput {
body: String!
author: User! @provides(fields: "username")
product: Product!
updated: DateTime!
inputType: AlphaNumeric!
}
type Review {
id: ID!
created: DateTime!
body: String!
author: User!
product: Product!
created: DateTime!
updated: DateTime!
inputType: AlphaNumeric!
}
Expand All @@ -502,7 +603,7 @@ const (
reviews: [Review]
}
union AlphaNumeric = Int | String | Float
union AlphaNumeric = Float | String | Int
`

productAndExtendsDirectivesFederatedSchema = `
Expand All @@ -511,9 +612,9 @@ const (
}
enum Satisfaction {
UNHAPPY,
HAPPY,
NEUTRAL,
UNHAPPY,
}
scalar CustomScalar
Expand All @@ -524,14 +625,21 @@ const (
GROCERIES,
}
interface ProductInfo {
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
scalar BigInt
type Product {
type Product implements ProductInfo {
upc: String!
name: String!
price: Int!
worth: BigInt!
reputation: CustomScalar!
departments: [Department!]!
averageSatisfaction: Satisfaction!
}
scalar DateTime
Expand Down

0 comments on commit de97afa

Please sign in to comment.