by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 20:29
    elauffenburger commented #592
  • Jan 31 2019 19:33
    bugged84 opened #1004
  • Jan 31 2019 19:24
    bugged84 edited #1003
  • Jan 31 2019 02:29
    joemcbride closed #1003
  • Jan 31 2019 02:29
    joemcbride commented #1003
  • Jan 31 2019 02:23
    bugged84 opened #1003
  • Jan 30 2019 20:04
    KoditkarVedant commented #160
  • Jan 30 2019 13:20
    sungam3r opened #1002
  • Jan 28 2019 22:35
    KoditkarVedant commented #980
  • Jan 28 2019 22:31
    KoditkarVedant synchronize #980
  • Jan 28 2019 20:57
    joemcbride labeled #1001
  • Jan 28 2019 20:57
    joemcbride commented #1001
  • Jan 28 2019 20:50
    sungam3r opened #1001
  • Jan 28 2019 17:32
    joemcbride commented #980
  • Jan 28 2019 17:28
    joemcbride commented #998
  • Jan 28 2019 17:27
    joemcbride commented #998
  • Jan 28 2019 17:27
    joemcbride commented #998
  • Jan 27 2019 20:46
    KoditkarVedant edited #1000
  • Jan 27 2019 20:45
    KoditkarVedant commented #1000
  • Jan 27 2019 20:43
    KoditkarVedant synchronize #1000
Aaron Edwards
@aaronjedwards
hate to be that guy but... @joemcbride can you provide any direction on this? Im wondering if I need to pump the breaks on using dotnet core 3.1 given this library might not be ready for use with it? I currently have a custom setup similar to the "AspNetCoreCustom" (dotnet core 2.2) example that is provided and would like to continue this approach in 3.1.
Joe McBride
@joemcbride

@aaronjedwards The only major thing, besides general breaking changes in the latest pre-release, is the changes to ASP.NET Core related to JSON.NET. You can still use JSON.NET, but have to allow synchronous IO, AllowSynchronousIO = true. The latest pre-release has broken out the use of JSON.NET into a different library, and you can use JSON.NET or System.Text.Json. The server project uses 3.1 without issue.

See these related issues:
graphql-dotnet/graphql-dotnet#1116
graphql-dotnet/graphql-dotnet#1148

Aaron Edwards
@aaronjedwards
@joemcbride Thanks for the references. Got it, I have used a customized setup historically without using graphql-dotnet/server so maybe I just need to familiarize myself with using it and how I can achieve the same customizations (eg. validation rules, authentication, dataloader, etc.)
Joe McBride
@joemcbride
@aaronjedwards If you don’t need subscriptions, using a customized solution is fine (and is what I prefer myself). The server project does add a few nice things, but much harder to customize.
Aaron Edwards
@aaronjedwards
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using GraphAPI;
using GraphQL;
using GraphQL.DataLoader;
using GraphQL.Http;
using GraphQL.Instrumentation;
using GraphQL.Types;
using GraphQL.Validation;
using GraphQL.Validation.Complexity;
using GraphQL.Validation.Rules;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;

namespace API.Controllers
{
    [Route("api/graphql")]
    [ApiController]
    public class GraphQLController : ControllerBase
    {
        private readonly ISchema _schema;
        private readonly IDocumentExecuter _executer;
        private readonly IDocumentWriter _writer;
        private readonly IServiceProvider _provider;

        public GraphQLController(IDocumentExecuter executer, IDocumentWriter writer, ISchema schema, IServiceProvider provider)
        {
            _executer = executer;
            _writer = writer;
            _schema = schema;
            _provider = provider;
        }

        [HttpPost]
        public async Task PostAsync()
        {
            var request = Deserialize<GraphQLRequest>(Request.Body);
            var inputs = request.Variables.ToInputs();
            var queryToExecute = request.Query;
            var dataLoaderListener = _provider.GetRequiredService<DataLoaderDocumentListener>();

            var rules = new List<IValidationRule> { new ProvidedNonNullArguments(), new ArgumentsOfCorrectType() }.Concat(DocumentValidator.CoreRules());

            var result = await _executer.ExecuteAsync(_ =>
            {
                _.Schema = _schema;
                _.Query = queryToExecute;
                _.OperationName = request.OperationName;
                _.Inputs = inputs;
                _.Listeners.Add(dataLoaderListener);
                _.ComplexityConfiguration = new ComplexityConfiguration { MaxDepth = 15 };
                _.FieldMiddleware.Use<InstrumentFieldsMiddleware>();
                _.UserContext = new GraphQLUserContext { User = Request.HttpContext.User };
                _.ValidationRules = rules;
                _.ExposeExceptions = true;

            }).ConfigureAwait(false);

            Response.ContentType = "application/json";
            Response.StatusCode = result.Errors?.Any() == true ? (int)HttpStatusCode.BadRequest : (int)HttpStatusCode.OK;
            await _writer.WriteAsync(Response.Body, result);
        }

        public static T Deserialize<T>(Stream s)
        {
            using (var reader = new StreamReader(s))
            using (var jsonReader = new JsonTextReader(reader))
            {
                var ser = new JsonSerializer();
                return ser.Deserialize<T>(jsonReader);
            }
        }
    }
}
@joemcbride I would be looking for a setup similar to this. would that mean simply (enough) swapping out the Deserialize method to use System.Text.Json instead?
Joe McBride
@joemcbride
@aaronjedwards Yes - the abstraction we currently took is to build the System.Text.Json/ NewtonSoft.Json into the IDocumentWriter interface. So you would add GraphQL.SystemTextJson nuget and register the DocumentWriter class as that interface in your services.
Aaron Edwards
@aaronjedwards
@joemcbride You mean for serialization only correct? Im thinking I would still need to manually deserialize the request.
Joe McBride
@joemcbride
@aaronjedwards Correct. You would need to still manually deserialize the request, however you decide to do that. You could keep that as Newtonsoft if you want, but would probably have to set that AllowSynchronousIO.
Aaron Edwards
@aaronjedwards
@joemcbride Thanks for the insight. I think I will go with the System.Text.Json approach to steer clear of any synchronous behavior.
Joe McBride
@joemcbride
:+1:
madhusnagaraj
@madhusnagaraj
Hi All, I am trying out an GraphQL implementation. One important aspect is to have Open documentation like swagger. I am wondering if there a way to expose the UI playground or Voyager for documentation purposes in production where the endpoint would be secured.
Gurdeep Sira
@gurdeepsira
Hi guys does Graphql-dotnet support federation? Last I read about this was that it was in discussion, but nothing since.
Jake Howard
@jhoward321
Hi guys, are there any plans to push a new preview package to nuget? I'm trying to use this fluent validation library, but it requires a newer version than is published in nuget. Unfortunately using the myget feed is going to be problematic for my build pipeline.
myermian
@myermian

Hello everyone, I'm a bit new to GraphQL (been playing around with it for 2 days now). I created a .NET Core 3.1 Web App. I have existing libraries for my models and my data repository. I verified that these work by utilizing REST endpoints to return my data.

I want to expose a GraphQL endpoint, so I added the necessary GraphQL packages. If I want to start working with GraphQL, do I have to create a copy of all my model classes, but extended from the appropriate GraphQL classes? In the examples, all of the StarWars classes extend some GraphQL class. In my project currently, all my models are POCO. I don't mind writing a few classes necessary, but when I have around 100+ POCO model classes that build up an object graph, I really don't want to rewrite those.

Ted Senft
@robotgryphon
Evening; I'm trying to follow the docs and use the 3.x preview versions with a new core 3.1 project, but I'm getting errors with the AddSystemTextJson part of the setup chain. The packages are all added?
myermian
@myermian
Ted, took me awhile to get it going, what's the error you are stuck on?
@robotgryphon use a mention when you get back so I can get alerted.
Ted Senft
@robotgryphon
@myermian I think I finally got it, actually. Looks like I kept trying to add the wrong deserializer, needed the Server.Transports.AspNetCore.SystemTextJson one.
image.png
Is there a way to turn off this tracing?
myermian
@myermian
Not sure about turning off tracing, but yea, for AspNet projects you need the AspNetCore version of SystemTextJson
I also found that you have to have matching versions, at least, that's how it worked for me:
<PackageReference Include="GraphQL" Version="3.0.0-preview-1490" />
<PackageReference Include="GraphQL-Parser" Version="5.1.2" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="3.5.0-alpha0046" />
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="3.5.0-alpha0046" />
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="3.4.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="3.4.0" />
<PackageReference Include="GraphQL.SystemTextJson" Version="3.0.0-preview-1490" />
maybe the tracing is only for the playground?
Ted Senft
@robotgryphon
Seemingly so, yeah. Found out there's a PlaygroundSettings option and some docs on it.
Dean Milojevic
@DeanMilojevic

Hi all,

I wanted to check on some indication when the packages (the ones mentioned in couple posts above) are going to be in some stable release? I recently introduced the graphql-dotnet into one of the projects as PoC and hit the issue with serializers and Newtonsoft.Json. So for time being, as it is PoC, no issues to use alpha packages. Long term tho, not so much.

Thanks for the help ;)

Nicolai Linde
@bar10dr_gitlab
image.png
Am I doing this the right way?
Nicolai Linde
@bar10dr_gitlab
Or is it more proper to create a query per specific function instead of making all fields arguments
IlluminatedNight
@illuminatednight
This is my first Gitter-chat. Hello!
I'm currently struggling to find how to resolve "No service for type 'GraphQL.Types.EnumerationGraphType' has been registered". I'm using the GraphType First approach and haven't defined a specific graph type for the enum I'm trying to expose.
IlluminatedNight
@illuminatednight

If I create public class MyStatusEnum : EnumerationGraphType<StatusEnum> { }

the error changes to "Cannot resolve scoped service 'my_project.Models.MyStatusEnum' from root provider."

Field(d => d.Status, type: typeof(MyStatusEnum));
Dan Sherwood
@Teletraan1
Have you registered MyStatusEnum as a singleton in your Startup.cs?
Nicolai Linde
@bar10dr_gitlab
Currently I have a lot of Field declarations in a MapQuery : ObjectGraphType function, that gets fed into a GraphSchema(IDependencyResolver resolver) : base(resolver) method.
I want to split the Field declarations into separate files, so every Field declaration isn't mashed together in one single method.
What would be the best way to accomplish that?
Nicolai Linde
@bar10dr_gitlab
Using ObjectGraphType.Fields and ObjectGraphType.AddField I should be able to make it work I assume, is that the best way to do it?
IlluminatedNight
@illuminatednight
@Teletraan1 that was what fixed it, thanks!
IlluminatedNight
@illuminatednight
Is it by design that GraphQL doesn't have method overloading/polymorphism? I'm trying to figure out what to do with a method name that has two different argument lists in our web API when converting it to a GraphQL resolver
IlluminatedNight
@illuminatednight
Ok well, for now I am changing the GraphQLMetadata method name but keeping the resolvers as is
I just can't help but feel I'm not completely grasping the power of GraphQL yet. I should be writing less resolver methods than the webAPI methods that existed in the previous controller.
Victor Nagy
@galaxyAbstractor

Hey all! I'm having lots of trouble with scoped services in our ObjectGraphTypes and field resolvers.

Our services needs to be registered as scoped services, but since the schema is registered as a singleton, our queries and types as well are singletons, so we cannot inject our services in the constructor due to the scoping issues.

We cannot inject a IServiceProvider into the ObjectGraphType either and create a scope there, because some of our services hold a cache of already processed work for that request. Had we created scopes in the resolver methods of our ObjectGraphTypes, a new scope would be created for each and every item in a list of entities.

What I did end up doing, by some suggestions in an issue on github, is that in my GraphQLController where the executer is executed, I inject an IServiceProvider into the controller and store it in our UserContext dictionary, so that it can be accessed later in the queries and types from the ResolveFieldContext. This seems to work fine, a scope is now equal to a single request and is properly disposed after the request is done.

The issue is that we are also using Subscriptions, which uses the same ObjectGraphTypes as well where UserContext is not controllable by us, because the MessageHandlingContext is sent there instead. MessageHandlingContext does let you put things in it's properties by implementing a IOperationMessageListener though, which I have done. Trying however to add a IServiceProvider to it seems to break the subscription in very weird ways (suddenly complaining that our schema cannot be parsed and is missing types). I can however store a IServiceScope by using createScope() on the injected service provider, but I dunno how this would be properly disposed of. My thought would be maybe when the web socket is terminated. Any ideas? Are we maybe doing it the wrong way?

Sorry for the long post

Victor Nagy
@galaxyAbstractor
Well obviously now that I tried my middleware, doing context.Properties["SERVICE_SCOPE"] = _serviceProvider.CreateScope(); obviously don't work because the scope is immediately-ish disposed
Matthew O'Connor
@oconnor0

I have been working through some of the intro GraphQL.Net "tutorial" stuff. Specifically, I have been taking the following, and then trying to create the schema programmatically. So to turn this:

public class Query 
{
    [GraphQLMetadata("jedis")]
    public IEnumerable<Jedi> GetJedis() 
    {
        return StarWarsDB.GetJedis();
    }

    // etc
}

// elsewhere

var schema = Schema.For(@"
  type Jedi {
    name: String
    side: String
  }

  type Query {
    jedis: [Jedi]
    jedi(id: ID): Jedi
  }
", _ => {
    _.Types.Include<Query>();
});

Into this:

var schema = new GraphQL.Types.Schema();

var query = new GraphQL.Types.ObjectGraphType();
query.Name = "Query";
schema.RegisterType(query);
schema.Query = query;

var jedi = new GraphQL.Types.ObjectGraphType();
jedi.Name = "Jedi";
schema.RegisterType(jedi);

var jediName = new GraphQL.Types.FieldType();
jediName.Name = "name";
jediName.ResolvedType = schema.FindType("String");
jedi.AddField(jediName);

// etc

Obviously this isn't "better", but I plan to generate a schema dynamically after I figure out the pieces manually.
But I haven't been able to figure out how to do the equivalent of _.Types.Include<Query>(); when programmatically creating the schema.

Aaron Edwards
@aaronjedwards
@joemcbride are there any major updates on progress towards the release of v3?
Matthew O'Connor
@oconnor0
Ah, Resolver and GraphQL.Resolvers.FuncFieldResolver. :)
Moh Moh Oo
@mohmohoo
I am looking for unit tests for usage on this method in FieldBuilder class. public FieldBuilder<TSourceType, TReturnType> Configure(Action<FieldType> configure);
Could anyone please help me? I have already looked at this unit test class for this and couldnt find the test. https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL.Tests/Builders/FieldBuilderTests.cs
Aaron Edwards
@aaronjedwards
For some reason in v3 preview I am getting the following error whenever I include variables in my query/mutation:
System.Reflection.TargetParameterCountException: Parameter count mismatch.
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at GraphQL.ObjectExtensions.<>c__DisplayClass8_0.<AsDictionary>b__1(PropertyInfo propInfo) in C:\projects\graphql-dotnet\src\GraphQL\ObjectExtensions.cs:line 337
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](TSource[] source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at GraphQL.ObjectExtensions.AsDictionary(Object source, BindingFlags flags) in C:\projects\graphql-dotnet\src\GraphQL\ObjectExtensions.cs:line 331
   at API.GraphQL.GraphQLExtensions.ToInputs(Object obj) in