Skip to content

dlukez/graphql-dotnet-annotations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6c6ffa8 · Sep 5, 2021

History

28 Commits
Sep 5, 2021
Sep 5, 2021
Sep 5, 2021
Sep 5, 2021
Feb 16, 2017
Feb 16, 2017
Feb 12, 2017
Sep 5, 2021
Jan 30, 2017
Feb 16, 2017
Apr 10, 2017
Sep 5, 2021
Apr 10, 2017

Repository files navigation

GraphQL.Annotations

NuGet MyGet Pre Release MyGet Build Status

Attribute-based schema definitions for GraphQL in .NET.

Have a look through the sample app and leave some feedback.

Running the sample app

cd samples/GraphQL.Annotations.StarWarsApp/
dotnet build
dotnet ef database update
dotnet run

Annotating your models

Full example

// Model/QueryRoot.cs

[GraphQLObject]
public class QueryRoot : IDisposable
{
    public StarWarsContext Db = new StarWarsContext();

    [GraphQLFunc]
    public IEnumerable<Droid> Droids(ResolveFieldContext context)
    {
        var db = context.GetDataContext();
        return db.Droids.ToList();
    }

    [GraphQLFunc]
    public IEnumerable<Human> Humans(ResolveFieldContext context)
    {
        var db = context.GetDataContext();
        return db.Humans.ToList();
    }

    public void Dispose()
    {
        Db.Dispose();
    }
}

// Model/Droid.cs

[GraphQLObject]
public class Droid : ICharacter
{
    [GraphQLField]
    public int DroidId { get; set; }

    [GraphQLField]
    public string Name { get; set; }

    [GraphQLField]
    public string PrimaryFunction { get; set; }

    [GraphQLFunc]
    public IEnumerable<ICharacter> Friends(ResolveFieldContext context)
    {
        var db = context.GetDataContext();
        return db.Friendships
            .Where(f => f.DroidId == ((Droid)context.Source).DroidId)
            .Select(f => f.Human);
    }
}

Todo

  • Include Scalar example.
  • Fill out this readme.

About

Attribute-based schema definitions for GraphQL in .NET.

Resources

License

Stars

Watchers

Forks

Packages

No packages published