Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Schema refinements (#17)
Browse files Browse the repository at this point in the history
* Started to refine Types

* ...

* ...

* Input non nullable

* move add field game

* cleanup usings

* Introduce Schema Builder

* schema test

* sonar

* ...

* ...

* remove VsCode folder

* Update SchemaBuilder.cs
  • Loading branch information
RohrerF authored May 20, 2019
1 parent 5f52713 commit 21f366f
Show file tree
Hide file tree
Showing 28 changed files with 316 additions and 116 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

### Code ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### Csharp ###
## Ignore Visual Studio temporary files, build results, and
Expand Down
34 changes: 0 additions & 34 deletions .vscode/launch.json

This file was deleted.

36 changes: 0 additions & 36 deletions .vscode/tasks.json

This file was deleted.

2 changes: 0 additions & 2 deletions src/Abstractions/Move.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace UltimateTicTacToe.Abstractions
{
public class Move
Expand Down
37 changes: 37 additions & 0 deletions src/Api.Tests/Api.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>UltimateTicTacToe.Api.Tests</AssemblyName>
<RootNamespace>UltimateTicTacToe.Api.Tests</RootNamespace>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>


<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>Portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Snapshooter.Xunit" Version="0.4.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.msbuild" Version="2.5.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Api\Api.csproj" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions src/Api.Tests/SchemaBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Xunit;
using Snapshooter.Xunit;
using HotChocolate.Types;
using UltimateTicTacToe.Api.Types;

namespace UltimateTicTacToe.Api.Tests
{
public class SchemaBuilderTests
{
[Fact]
public void Ensure_Schema_IsCorrect()
{
// arrange
var schema = SchemaBuilder.BuildSchema();

// act
string schemaSDL = schema.ToString();

// assert
Snapshot.Match(schemaSDL);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
schema {
query: Query
mutation: Mutation
}

type Game {
id: ID!
moves: [Move!]!
winner: Winner
finishedAt: Date
}

type Move {
id: ID!
boardPosition: Position!
tilePosition: Position!
player: Player!
moveNumber: Int!
game: Game!
}

type MoveResult {
isValid: Boolean!
move: Move!
invalidReason: String!
moveFinishedBoard: Boolean!
moveFinishedGame: Boolean!
}

type Mutation {
createGame: Game!
move(input: MoveInput!): MoveResult!
}

type Position {
x: Int!
y: Int!
equals: Boolean!
}

type Query {
game(id: ID!): Game
}

input MoveInput {
gameId: ID!
player: Player!
boardPosition: PositionInput!
tilePosition: PositionInput!
}

input PositionInput {
x: Int!
y: Int!
}

enum Player {
CROSS
CIRCLE
}

enum Winner {
CROSS
CIRCLE
NONE
DRAW
}

"The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text."
scalar String

"The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID."
scalar ID

"The `Boolean` scalar type represents `true` or `false`."
scalar Boolean

"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."
scalar Int

"The `Date` scalar represents an ISO-8601 compliant date type."
scalar Date
18 changes: 9 additions & 9 deletions src/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="0.8.1"/>
<PackageReference Include="HotChocolate.Subscriptions.InMemory" Version="0.8.1"/>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="0.8.1"/>
<PackageReference Include="HotChocolate" Version="0.8.1"/>
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="0.8.1" />
<PackageReference Include="HotChocolate.Subscriptions.InMemory" Version="0.8.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="HotChocolate.AspNetCore" Version="0.8.1" />
<PackageReference Include="HotChocolate" Version="0.8.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Abstractions\Abstractions.csproj"/>
<ProjectReference Include="..\Data.Abstractions\Data.Abstractions.csproj"/>
<ProjectReference Include="..\Data\Data.csproj"/>
<ProjectReference Include="..\Domain\Domain.csproj"/>
<ProjectReference Include="..\Abstractions\Abstractions.csproj" />
<ProjectReference Include="..\Data.Abstractions\Data.Abstractions.csproj" />
<ProjectReference Include="..\Data\Data.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/Api/Input/MoveInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ namespace UltimateTicTacToe.Api.Input
public class MoveInput
{
public string GameId { get; set; }

[GraphQLNonNullType]
public Position BoardPosition { get; set; }

[GraphQLNonNullType]
public Position TilePosition { get; set; }
public Player Player { get; set; }

[GraphQLIgnore]
public Move ToMove()
{
return new Move
Expand Down
1 change: 0 additions & 1 deletion src/Api/Query.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using HotChocolate;
Expand Down
13 changes: 1 addition & 12 deletions src/Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using HotChocolate.AspNetCore;
using HotChocolate.Execution;
using HotChocolate.Execution.Configuration;
using HotChocolate.Subscriptions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -30,17 +29,7 @@ public void ConfigureServices(IServiceCollection services)

//services.AddInMemorySubscriptionProvider();

Schema schema = Schema.Create(c =>
{
//GraphQL Types
c.RegisterQueryType<QueryType>();
c.RegisterMutationType<MutationType>();
// c.RegisterSubscriptionType<SubscriptionType>();
c.RegisterExtendedScalarTypes();

//Custom Types
c.RegisterType<GameType>();
});
Schema schema = SchemaBuilder.BuildSchema();

services.AddGraphQL(schema.MakeExecutable(c =>
c.UseDefaultPipeline(new QueryExecutionOptions
Expand Down
1 change: 0 additions & 1 deletion src/Api/Types/GameType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using HotChocolate.Types;
using UltimateTicTacToe.Abstractions;
using UltimateTicTacToe.Data.Abstractions;
Expand Down
21 changes: 21 additions & 0 deletions src/Api/Types/MoveInputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using HotChocolate.Types;
using UltimateTicTacToe.Abstractions;
using UltimateTicTacToe.Api.Input;

namespace UltimateTicTacToe.Api.Types
{
public class MoveInputType : InputObjectType<MoveInput>
{
protected override void Configure(IInputObjectTypeDescriptor<MoveInput> descriptor)
{
descriptor
.Field(m => m.GameId)
.Type<NonNullType<IdType>>();

descriptor
.Field(m => m.Player)
.Type<NonNullType<EnumType<Player>>>();

}
}
}
32 changes: 32 additions & 0 deletions src/Api/Types/MoveResultType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HotChocolate.Types;
using UltimateTicTacToe.Domain.Abstractions;

namespace UltimateTicTacToe.Api.Types
{
public class MoveResultType : ObjectType<MoveResult>
{
protected override void Configure(
IObjectTypeDescriptor<MoveResult> descriptor)
{
descriptor
.Field(m => m.IsValid)
.Type<NonNullType<BooleanType>>();

descriptor
.Field(m => m.Move)
.Type<NonNullType<MoveType>>();

descriptor
.Field(m => m.InvalidReason)
.Type<NonNullType<StringType>>();

descriptor
.Field(m => m.MoveFinishedBoard)
.Type<NonNullType<BooleanType>>();

descriptor
.Field(m => m.MoveFinishedGame)
.Type<NonNullType<BooleanType>>();
}
}
}
Loading

0 comments on commit 21f366f

Please sign in to comment.