C# Library for adding objects which map to TSQL Tables to a graphql schema, Intended to be used with the GraphQL package on nuget. A sample project is included with the db schema required to run it. The client side code is based on the react ui from haikyuu/graphql-todo-list
If you get confused with these instructions refer to the GraphQL.Annotations.ToDo.Example
project
- Add the GraphQL.Annotations.TSql nuget package
- Create your schema, query, and mutation objects and add them to DI
- Add
IServiceProvider
as a constructor parameter to both your Query and Mutation types - Add
this.AddGraphQLTSqlMutationFields<Mutation>(serviceProvider);
inside the constructor of the mutation class - Add
this.AddGraphQLTSqlQueryFields<Query>(serviceProvider);
inside the constructor of the query class. - Add
services.AddGraphQLTSql<Query, Mutation>();
inside your Startup.ConfigureServices method - Create a class implementing
ISqlConnectionGetter
and add it to DI using the interface. This class will be used to create all connections, the return value of theGetConnection
method will be automatically disposed - If you are using the GraphQL.Server package with Asp.Net
- Add the
GraphQL.Annotations.TSql.AspNetCore
package - Add
.AddHttpContextUserContextBuilder()
to the end of yourservices.AddGraphQL
call
- Add the
This library is based on the GraphQL.Annotations library and uses similar syntax
This is the simpler case and will only add the object to your query type
- Inherit from
SqlFieldResolver<T>
filling in the class name as the type argument - Create properties and annotate them using SqlGraphQLField. Each field must be nullable otherwise you will run into
runtime errors
- You should not start any of your fields with an
_
all system fields will start with one and using them will potentially result in naming conflicts
- You should not start any of your fields with an
- Implement the
Table
,DefaultOrder
, andPrimaryProperty
propertiesTable
is the table or view that this object is bound toDefaultOrder
is the property which will be used for ordering by default. Use the property name, not the sql field namePrimaryProperty
is the field which contains the primary key. Use the property name, not the sql field name. This MUST return a unique value per row, it is advised that this is also indexed
- Add the
GraphQLObject
attribute to the class
These are a little more involved documentation is in the wiki
The documentation for querying should be in the resulting graphql schema. Some of the potential problems and things to watch out for are in the wiki
Additional features can be found in the wiki.
All Pull Requests should be available as a prerelease on nuget.org. To create an official release create a release in github with the new version number, after the build completes it will be uploaded to nuget.org