Skip to content

Commit

Permalink
Update schema exporter tests (#3950)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jun 2, 2024
1 parent dde6aff commit dfd5bf1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extend type Category @key(fields: "id") {
id: ID! @external
products: [Product!]!
}

type Product @key(fields: "id") {
category: Category!
id: ID!
name: String!
category: Category!
}

extend type Category @key(fields: "id") {
id: ID! @external
products: [Product!]!
}

extend type Query {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
directive @extends on INTERFACE | OBJECT

directive @external on FIELD_DEFINITION

directive @requires(fields: String!) on FIELD_DEFINITION
directive @key(fields: String!) on INTERFACE | OBJECT

directive @provides(fields: String!) on FIELD_DEFINITION

directive @key(fields: String!) on OBJECT | INTERFACE

directive @extends on OBJECT | INTERFACE

scalar _Any

extend type Category @key(fields: "id") {
id: ID! @external
products: [Product!]!
}
directive @requires(fields: String!) on FIELD_DEFINITION

type Product @key(fields: "id") {
category: Category!
id: ID!
name: String!
category: Category!
}

extend type Query {
products: [Product!]!
_service: _Service!
_entities(representations: [_Any!]!): [_Entity]!
}
scalar _Any

"A union of all types that use the @key directive"
union _Entity = Category | Product

type _Service {
sdl: String
}

extend type Category @key(fields: "id") {
id: ID! @external
products: [Product!]!
}

extend type Query {
products: [Product!]!
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,27 @@ schema {
mutation: Mutation
}

type Query {
hero: Character
human(
"id of the human"
id: String!): Human
droid(
"id of the droid"
id: String!): Droid
}

interface Character {
"Which movie they appear in."
appearsIn: [Episode]
friends: [Character]
friendsConnection: CharacterInterfaceConnection
"The id of the character."
id: String!
"The name of the character."
name: String
friends: [Character]
friendsConnection: CharacterInterfaceConnection
"Which movie they appear in."
appearsIn: [Episode]
}

"A connection from an object to a list of objects of type `CharacterInterface`."
type CharacterInterfaceConnection {
"A count of the total number of objects in this connection, ignoring pagination. This allows a client to fetch the first five objects by passing \"5\" as the argument to `first`, then fetch the total count so it could display \"5 of 83\", for example. In cases where we employ infinite scrolling or don't have an exact count of entries, this field will return `null`."
totalCount: Int
"Information to aid in pagination."
pageInfo: PageInfo!
"A list of all of the edges returned in the connection."
edges: [CharacterInterfaceEdge]
"A list of all of the objects returned in the connection. This is a convenience field provided for quickly exploring the API; rather than querying for \"{ edges { node } }\" when no edge data is needed, this field can be used instead. Note that when clients like Relay need to fetch the \"cursor\" field on the edge to enable efficient pagination, this shortcut cannot be used, and the full \"{ edges { node } } \" version should be used instead."
items: [Character]
}

"Information about pagination in a connection."
type PageInfo {
"When paginating forwards, are there more items?"
hasNextPage: Boolean!
"When paginating backwards, are there more items?"
hasPreviousPage: Boolean!
"When paginating backwards, the cursor to continue."
startCursor: String
"When paginating forwards, the cursor to continue."
endCursor: String
"Information to aid in pagination."
pageInfo: PageInfo!
"A count of the total number of objects in this connection, ignoring pagination. This allows a client to fetch the first five objects by passing \"5\" as the argument to `first`, then fetch the total count so it could display \"5 of 83\", for example. In cases where we employ infinite scrolling or don't have an exact count of entries, this field will return `null`."
totalCount: Int
}

"An edge in a connection from an object to another object of type `CharacterInterface`."
Expand All @@ -57,66 +35,88 @@ type CharacterInterfaceEdge {
node: Character
}

"One of the films in the Star Wars Trilogy."
enum Episode {
"Released in 1977."
NEWHOPE
"Released in 1980."
EMPIRE
"Released in 1983."
JEDI
}

type Human implements Character {
"The id of the human."
id: String!
"The name of the human."
name: String
"A mechanical creature in the Star Wars universe."
type Droid implements Character {
"Which movie they appear in."
appearsIn: [Episode]
friends: [Character]
"A list of a character's friends."
friendsConnection(
"Only return edges after the specified cursor."
after: String,
"Specifies the maximum number of edges to return, starting after the cursor specified by 'after', or the first number of edges if 'after' is not specified."
first: Int,
"Only return edges prior to the specified cursor."
before: String,
"Specifies the maximum number of edges to return, starting after the cursor specified by 'after', or the first number of edges if 'after' is not specified."
first: Int,
"Specifies the maximum number of edges to return, starting prior to the cursor specified by 'before', or the last number of edges if 'before' is not specified."
last: Int): CharacterInterfaceConnection
"Which movie they appear in."
appearsIn: [Episode]
"The home planet of the human."
homePlanet: String
}

"A mechanical creature in the Star Wars universe."
type Droid implements Character {
"The id of the droid."
id: String!
"The name of the droid."
name: String
"The primary function of the droid."
primaryFunction: String
}

"One of the films in the Star Wars Trilogy."
enum Episode {
"Released in 1980."
EMPIRE
"Released in 1983."
JEDI
"Released in 1977."
NEWHOPE
}

type Human implements Character {
"Which movie they appear in."
appearsIn: [Episode]
friends: [Character]
"A list of a character's friends."
friendsConnection(
"Only return edges after the specified cursor."
after: String,
"Specifies the maximum number of edges to return, starting after the cursor specified by 'after', or the first number of edges if 'after' is not specified."
first: Int,
"Only return edges prior to the specified cursor."
before: String,
"Specifies the maximum number of edges to return, starting after the cursor specified by 'after', or the first number of edges if 'after' is not specified."
first: Int,
"Specifies the maximum number of edges to return, starting prior to the cursor specified by 'before', or the last number of edges if 'before' is not specified."
last: Int): CharacterInterfaceConnection
"Which movie they appear in."
appearsIn: [Episode]
"The primary function of the droid."
primaryFunction: String
"The home planet of the human."
homePlanet: String
"The id of the human."
id: String!
"The name of the human."
name: String
}

input HumanInput {
homePlanet: String
name: String!
}

type Mutation {
createHuman(human: HumanInput!): Human
}

input HumanInput {
name: String!
homePlanet: String
"Information about pagination in a connection."
type PageInfo {
"When paginating forwards, the cursor to continue."
endCursor: String
"When paginating forwards, are there more items?"
hasNextPage: Boolean!
"When paginating backwards, are there more items?"
hasPreviousPage: Boolean!
"When paginating backwards, the cursor to continue."
startCursor: String
}

type Query {
droid(
"id of the droid"
id: String!): Droid
hero: Character
human(
"id of the human"
id: String!): Human
}
6 changes: 3 additions & 3 deletions src/GraphQL.Tests/Utilities/SchemaExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public void StarWarsSchema()
serviceCollection.AddSingleton<GraphQL.StarWars.StarWarsData>();
var services = serviceCollection.BuildServiceProvider();
var schema = services.GetRequiredService<ISchema>();
schema.Print().ShouldMatchApproved(o => o.NoDiff());
schema.Print(new() { StringComparison = StringComparison.OrdinalIgnoreCase }).ShouldMatchApproved(o => o.NoDiff());
}

[Fact]
public void Federation1Schema()
{
var schema = new FederatedSchemaBuilder()
.Build("Federated".ReadSDL());
schema.Print(new GraphQL.Utilities.PrintOptions { IncludeFederationTypes = false })
schema.Print(new() { IncludeFederationTypes = false, StringComparison = StringComparison.OrdinalIgnoreCase })
.ShouldMatchApproved(o => o.NoDiff());
}

Expand All @@ -70,7 +70,7 @@ public void Federation2Schema()
{
var schema = new FederatedSchemaBuilder()
.Build("Federated".ReadSDL());
schema.Print().ShouldMatchApproved(o => o.NoDiff());
schema.Print(new() { StringComparison = StringComparison.OrdinalIgnoreCase }).ShouldMatchApproved(o => o.NoDiff());
}

[Fact]
Expand Down

0 comments on commit dfd5bf1

Please sign in to comment.