locked
ASP.net core and graphQL RRS feed

  • Question

  • User1525382536 posted

    I have build an asp.net core project which get Rest API calls and return data.

    now I added a GraphQL option as well, and I have some issue not clear :

    1. when I run the project and go to http://localhost:61171/ui/playground 

    In my Query and Type class I put a breakpoint which I see something is calling this all the time over and and over.

    2. in my Type class I tried to set a Field which returns a List of Data

    a. I get an error :

    System.ArgumentException: 'The GraphQL type for Field: 'Items' on parent type: 'GetReportType' could not be derived implicitly.

    how should i set this field? is it possible to give the client to query only specific properties :

    public List<Report> Items { get; set; }
    
    
    public class Report
        {
            public string RefID{ get; set; }
            public DateTime CreateTime { get; set; }
            public string Text { get; set; }
    }

    ==>I solved this issue #2 by define: Field<ListGraphType<ReportType>>("items");

    3. how can i read a KEY which sent in the HEADER and called "MYKEY"

    ==> this is (#3) solved based on this https://stackoverflow.com/a/53214052/9698435

    in the Query class?

    thanks for the help

    Monday, June 1, 2020 9:20 PM

All replies

  • User-17257777 posted

    Hi wanttolearn1,

    now I added a GraphQL option as well, and I have some issue not clear :

    1. when I run the project and go to http://localhost:61171/ui/playground 

    In my Query and Type class I put a breakpoint which I see something is calling this all the time over and and over.

    2. in my Type class I tried to set a Field which returns a List of Data

    a. I get an error :

    System.ArgumentException: 'The GraphQL type for Field: 'Items' on parent type: 'GetReportType' could not be derived implicitly.

    how should i set this field? is it possible to give the client to query only specific properties :

    public List<Report> Items { get; set; }
    
    
    public class Report
        {
            public string RefID{ get; set; }
            public DateTime CreateTime { get; set; }
            public string Text { get; set; }
    }

    Your descripton is a little confusing. Can you share more related codes and show us the exact location of the error?

    Best Regards,

    Jiadong Meng

    Tuesday, June 2, 2020 8:18 AM
  • User1525382536 posted

    Hi jiadongm ,

    i hae solved issues 2+3.

    my last issue is why when I set a breakpoint in the next class's I see them called over and over (while there is nothing that call for a query)

    public class GetReportType : ObjectGraphType<ReportModel>
        {
            public GetReportType()
            {
                Field(t => t.Message);
                Field(t =>
                    t.Count).Description("number of items that will be returned");
    
                Field<ListGraphType<ReportType>>("items");
    
    
                /* Field(t =>
                     t.Items).Description("items that should be returned");*/
    
            }
        }

    and the second class 

    public class ReportType : ObjectGraphType<Report>
        {
            public ReportType()
            {
                Field(t => t.SendId);
                Field(t => t.SendTime);
                Field(t => t.FromNumber);
                Field(t => t.ToNumber);
                Field(t => t.Reference);
                Field(t => t.Status);
                Field(t => t.ErrorCode);
                Field(t => t.Credits);
            }
        }

    and the class public class GetReportQuery : ObjectGraphType is triggered all the time as well

    not clear why.

    this is my code in ConfigureServices

    services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(
                    s.GetRequiredService));
                services.AddScoped<GetReportSchema>();
                services.AddGraphQL(o =>
                {
                    o.ExposeExceptions = true;
                }).AddGraphTypes(ServiceLifetime.Scoped)
                    .AddUserContextBuilder(httpContext => httpContext.User);
                services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

    Tuesday, June 2, 2020 9:00 AM
  • User1525382536 posted

    I found the issue to #3

    schema.polling.interval call's the schema every 2000 milliseconds

    can I disable this via code?

    Tuesday, June 2, 2020 10:22 AM
  • User-17257777 posted

    Hi wanttolearn1,

    You can adjust the relevant settings in GraphQL Playground.

    For more details, refer to this link: https://stackoverflow.com/a/58040379/11965297

    Best Regards,

    Jiadong Meng

    Wednesday, June 17, 2020 9:15 AM
  • User1525382536 posted

    Hi i know that

    but i want to do it via code

    Saturday, June 20, 2020 5:21 PM