ASP.NET > GraphQL

3515 단어 GraphQLaspcore2
NuGet 추가 → GraphQL



graphql-dotnet/examples

startup.cs


// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{

    services.AddSingleton<IDocumentExecuter, DocumentExecuter>();
    var sp = services.BuildServiceProvider();
    services.AddSingleton<ISchema>(new VivaSchema(new FuncDependencyResolver(type => sp.GetService(type))));
}

모델



Sckema


using GraphQL;
using GraphQL.Types;

namespace NHLStats.Api.Models
{
    public class NHLStatsSchema : Schema
    {
        public NHLStatsSchema(IDependencyResolver resolver): base(resolver)
        {
            Query = resolver.Resolve<NHLStatsQuery>();
            Mutation = resolver.Resolve<NHLStatsMutation>();
        }
    }
}

Query



Mutation



IPlayerRepository



PlayerType


query NHLStatsQuery($id: Int!){
  player(id: $id){
    id
  }
}

PlayerRepository

좋은 웹페이지 즐겨찾기