INNER CODE UNIT · C#

schema

graphql-dotnet/authorization · src/BasicSample/Program.cs:24

var schema = Schema.For(definitions, builder => builder.Types.Include<Query>());

// Claims principal must look something like this to allow access.
// GraphQLUserContext.User alternates below for demonstration purposes.
int counter = 0;
var authorizedUser = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("role", "Admin") }));
var nonAuthorizedUser = new ClaimsPrincipal(new ClaimsIdentity());

while (true)
{
    string json = await schema.ExecuteAsync(options =>
    {
        options.Query = "{ viewer { id name } }";
        options.Root = new Query();
        options.ValidationRules = DocumentValidator.CoreRules.Concat(serviceProvider.GetServices<IValidationRule>());
        options.RequestServices = serviceProvider;
        options.User = counter++ % 2 == 0 ? authorizedUser : nonAuthorizedUser;
    }).ConfigureAwait(false);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…