-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stitch all the queries and mutation available into composite qu…
…eries and mutations
- Loading branch information
Showing
20 changed files
with
362 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using BusinessServices.Building; | ||
using GraphQL.Types; | ||
using GraphQLCore.Unions; | ||
using Models.DTOs; | ||
using Models.GraphQLTypes.Building; | ||
using Models.GraphQLTypes.Person; | ||
|
||
namespace Models.Types | ||
{ | ||
public class BuildingMutation : ObjectGraphType, IGraphMutator | ||
{ | ||
public BuildingMutation(IBuildingService service) | ||
{ | ||
Name = "BuildingMutation"; | ||
Description = "Actions to create, update and delete a Building"; | ||
|
||
Field<BuildingType>( | ||
"CreateBuilding", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<BuildingInputType>> { Name = "building" }), | ||
resolve: ctx => service.Add(ctx.GetArgument<BuildingModel>("building")), | ||
description: "Create a new Building" | ||
); | ||
|
||
Field<BuildingType>( | ||
"UpdateBuilding", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<BuildingInputType>> { Name = "building" }), | ||
resolve: ctx => service.Update(ctx.GetArgument<BuildingModel>("building")), | ||
description: "Update a Building" | ||
); | ||
|
||
Field<BuildingType>( | ||
"RemoveBuilding", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id" }), | ||
resolve: ctx => service.Delete(ctx.GetArgument<string>("id")), | ||
description: "Delete a Building" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using BusinessServices.Building; | ||
using GraphQL.Types; | ||
using GraphQLCore.Unions; | ||
using Models.GraphQLTypes.Building; | ||
|
||
namespace Models.Types | ||
{ | ||
public class BuildingQuery : ObjectGraphType, IGraphQueryMarker | ||
{ | ||
public BuildingQuery(IBuildingService service) | ||
{ | ||
Name = "BuildingQuery"; | ||
Description = "Actions fetch a Building"; | ||
|
||
Field<BuildingType>( | ||
"Building", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id" }), | ||
resolve: ctx => service.Get(ctx.GetArgument<string>("id")), | ||
description: "Fetch a Building by their Identifier" | ||
); | ||
|
||
Field<ListGraphType<BuildingType>>( | ||
"Buildings", | ||
resolve: ctx => service.GetAll(), | ||
description: "Fetch all Buildings" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using BusinessServices.Product; | ||
using GraphQL.Types; | ||
using GraphQLCore.Unions; | ||
using Models.GraphQLTypes.Product; | ||
|
||
namespace Models.Types | ||
{ | ||
public class ProductMutation : ObjectGraphType, IGraphMutator | ||
{ | ||
public ProductMutation(IProductService service) | ||
{ | ||
Name = "ProductMutation"; | ||
Description = "Actions to create, update and delete a Product"; | ||
|
||
Field<ProductType>( | ||
"CreateProduct", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<ProductInputType>> { Name = "Product" }), | ||
resolve: ctx => { | ||
// service.Add(ctx.GetArgument<ProductModel>("Product")) | ||
return null; | ||
}, | ||
description: "Create a new Product" | ||
); | ||
|
||
Field<ProductType>( | ||
"UpdateProduct", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<ProductInputType>> { Name = "Product" }), | ||
resolve: ctx => { | ||
// service.Update(ctx.GetArgument<ProductModel>("Product")); | ||
return null; | ||
}, | ||
description: "Update a Product" | ||
); | ||
|
||
Field<ProductType>( | ||
"RemoveProduct", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id" }), | ||
resolve: ctx => { | ||
// service.Delete(ctx.GetArgument<string>("id")); | ||
return null; | ||
}, | ||
description: "Delete a Product" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using BusinessServices.Product; | ||
using GraphQL.Types; | ||
using GraphQLCore.Unions; | ||
using Models.GraphQLTypes.Product; | ||
|
||
namespace Models.Types | ||
{ | ||
public class ProductQuery : ObjectGraphType, IGraphQueryMarker | ||
{ | ||
public ProductQuery(IProductService service) | ||
{ | ||
Name = "ProductnQuery"; | ||
Description = "Actions fetch a Product"; | ||
|
||
Field<ProductType>( | ||
"Product", | ||
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id" }), | ||
resolve: ctx => service.Get(ctx.GetArgument<string>("id")), | ||
description: "Fetch a Product by their Identifier" | ||
); | ||
|
||
Field<ListGraphType<ProductType>>( | ||
"Products", | ||
resolve: ctx => service.GetAll(), | ||
description: "Fetch all Products" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using GraphQL.Types; | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQLCore.Unions | ||
{ | ||
public class CompositeMutators : ObjectGraphType | ||
{ | ||
public CompositeMutators(IEnumerable<IGraphMutator> mutators) | ||
{ | ||
Name = "Mutators"; | ||
Description = "Actions with side-effects"; | ||
|
||
foreach (var query in mutators) | ||
{ | ||
var q = query as ObjectGraphType; | ||
foreach (var field in q.Fields) | ||
AddField(field); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using GraphQL.Types; | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQLCore.Unions | ||
{ | ||
public class CompositeQueries: ObjectGraphType | ||
{ | ||
public CompositeQueries(IEnumerable<IGraphQueryMarker> queries) | ||
{ | ||
Name = "Queries"; | ||
Description = "Read only fetch actions"; | ||
|
||
foreach (var query in queries) | ||
{ | ||
var q = query as ObjectGraphType; | ||
foreach(var field in q.Fields) | ||
AddField(field); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace GraphQLCore.Unions | ||
{ | ||
public interface IGraphMutator { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace GraphQLCore.Unions | ||
{ | ||
public interface IGraphQueryMarker { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using GraphQL.Types; | ||
using Models.Types; | ||
|
||
namespace GraphQLCore.Unions | ||
{ | ||
public class Mutations: UnionGraphType | ||
{ | ||
public Mutations() | ||
{ | ||
Type<PersonMutation>(); | ||
Type<ProductMutation>(); | ||
Type<BuildingMutation>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using GraphQL.Types; | ||
using Models.Types; | ||
|
||
namespace GraphQLCore.Unions | ||
{ | ||
public class Queries : UnionGraphType | ||
{ | ||
public Queries() | ||
{ | ||
Type<PersonQuery>(); | ||
Type<ProductQuery>(); | ||
Type<BuildingQuery>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using GraphQL.Types; | ||
|
||
namespace Models.GraphQLTypes.Person | ||
{ | ||
public class BuildingInputType : InputObjectGraphType | ||
{ | ||
public BuildingInputType() | ||
{ | ||
Name = "BuildingInput"; | ||
Field<NonNullGraphType<StringGraphType>>("name"); | ||
Field<NonNullGraphType<StringGraphType>>("address"); | ||
} | ||
} | ||
} |
Oops, something went wrong.