Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 03 21:22
    alekbarszczewski closed #2715
  • Dec 03 21:01
    sungam3r labeled #2627
  • Dec 03 20:04
    sungam3r labeled #2715
  • Dec 03 09:55
    alekbarszczewski opened #2715
  • Nov 30 11:15
    sungam3r synchronize #2712
  • Nov 29 23:24
    zcsizmadia synchronize #2712
  • Nov 29 23:18
    zcsizmadia synchronize #2712
  • Nov 29 23:00
    zcsizmadia synchronize #2712
  • Nov 29 22:20
    dependabot[bot] labeled #2714
  • Nov 29 22:20
    dependabot[bot] labeled #2714
  • Nov 29 22:20
    dependabot[bot] opened #2714
  • Nov 29 22:17
    zcsizmadia synchronize #2712
  • Nov 29 22:03
    dependabot[bot] labeled #2713
  • Nov 29 22:03
    dependabot[bot] labeled #2713
  • Nov 29 22:03
    dependabot[bot] opened #2713
  • Nov 29 21:26
    zcsizmadia synchronize #2712
  • Nov 29 20:39
    zcsizmadia synchronize #2712
  • Nov 29 20:22
    sungam3r milestoned #2712
  • Nov 29 20:22
    sungam3r labeled #2712
  • Nov 29 18:56
    zcsizmadia synchronize #2712
Oleg26Dev
@Oleg26Dev
An unhandled exception of type 'System.Net.WebSockets.WebSocketException' occurred in System.Private.CoreLib.dll
The server returned status code '500' when status code '101' was expected.
Mike
@veld:matrix.org
[m]
Hey folks, where can i read more about using async functions inside of graphQL.Server queries?
Mike
@veld:matrix.org
[m]
^ Found an answer to this, it's FieldAsync instead of Field
Sean Harding
@optimizasean
👍
Sean Harding
@optimizasean

Here is a lambda sample for you @veld:matrix.org :

namespace MyApp.Api.GraphQL {
    public partial class MyAppQuery: ObjectGraphType {
        private partial void Admins(ApplicationDbContext context, IDataLoaderContextAccessor dataLoaderAccessor) {
            FieldAsync<ListGraphType<UserGraphType>>(
                name: "Admins",
                arguments: new QueryArguments(
                    new QueryArgument<StringGraphType> { Name = "name" },
                    new QueryArgument<StringGraphType> { Name = "firstName" },
                    new QueryArgument<StringGraphType> { Name = "middleName" },
                    new QueryArgument<StringGraphType> { Name = "lastName" },
                    new QueryArgument<StringGraphType> { Name = "email" },
                    new QueryArgument<StringGraphType> { Name = "userName" }
                ),
                resolve: async resolver => {
                    IQueryable<User> query = context.Roles.Where(role => role.Name.Equals("Admin"))
                        .Join(
                            context.UserRoles,
                            role => role.Id,
                            userRole => userRole.RoleId,
                            (role, userRole) => userRole
                        ).Join(
                            context.Users,
                            roleClaim => roleClaim.UserId,
                            user => user.Id,
                            (roleClaim, user) => user
                        );

                    var name = resolver.GetArgument<string>("name");
                    var firstName = resolver.GetArgument<string>("firstName");
                    var middleName = resolver.GetArgument<string>("middleName");
                    var lastName = resolver.GetArgument<string>("lastName");
                    var email = resolver.GetArgument<string>("email");
                    var userName = resolver.GetArgument<string>("userName");

                    if (name != null) query = query.Where(u => (u.FirstName + " " + u.MiddleName + " " + u.LastName).Contains(name));
                    if (firstName != null) query = query.Where(u => u.FirstName.Contains(firstName));
                    if (middleName != null) query = query.Where(u => u.MiddleName.Contains(middleName));
                    if (lastName != null) query = query.Where(u => u.LastName.Contains(lastName));
                    if (email != null) query = query.Where(u => u.Email == email);
                    if (userName != null) query = query.Where(u => u.UserName == userName);

                    return await query.OrderBy(u => u.FirstName).ThenBy(u => u.MiddleName).ThenBy(u => u.LastName).ToListAsync();
                }
            );
        }
    }
}

Something like that is what I do to separate my queries into different files for ease of use. I would put that in a folder called Queries and name the file Admins.cs (same name as query), then register in main partial class (MyAppQuery class). This is using EntityFrameworkCore with GraphQL and the data loader package

Mike
@veld:matrix.org
[m]
oh! this is amazing, I'll take a look whenever I have some space
Mike
@veld:matrix.org
[m]
Cool! ok, I got some of this stuff up and running now! which is exciting.
ShawnAbshire
@ShawnAbshire
Hello - I'm using the GraphQL.Server.Transports.AspNetCore HTTP middleware to handle graphql requests to the server; however, I'm also trying to implement fluent validator to the application using the library GraphQL.FluentValidation (https://www.nuget.org/packages/GraphQL.FluentValidation) but I'm not really sure using the aspnet core middleware how I can extend the ExecutionOptions ... any thoughts?
Sean Harding
@optimizasean
I was looking at the FluentValidation packages too but am not too sure how to integrate with the middleware myself
ShawnAbshire
@ShawnAbshire
Yea I can't see a way to extend the ExecutionOptions of the aspnetcore middleware
Michael W Powell
@mwpowellhtx
hello all I am finding this gem... I would like to consider graphql for purposes of supporting identity management, security relationships. seems well suited to the task, but I need to know how to get started, with either postgres or sqlserver for data stores.
ideally, nodes might be things like user, role, membership or group (i.e. user assigned roles via membership), claims (i.e. can be held by users themselves, roles, or groups). well, you can see the relationships forming between them. seems like a fit to me.
Sean Harding
@optimizasean
I am using SQLServer + EntityFramework with GraphQL on top personally but you can use many different backings. I think most people use SQLServer but it depends on your use case and comfort with the back end.
ShawnAbshire
@ShawnAbshire

Just a follow up to the question I had before as I just circled back to it.

You can infact extend the execution options I believe by providing a middleware wrapper when calling UseGraphQL at startup. .UseGraphQL<Schema, GraphQlHttpMiddlewareWrapper<Schema>>()... and example they provide is logging details here: https://github.com/graphql-dotnet/server/blob/2ab8faaf71b5ec4a6075a9459c28436bcd14b881/samples/Samples.Server/GraphQLHttpMiddlewareWithLogs.cs

Sean Harding
@optimizasean
Oh nice!
srs6814
@srs6814

Hello,

I want to disable Introspection queries on the Production Environment,
I found this issue which is graphql-dotnet/graphql-dotnet#766

I am currently on GraphQL version 4.5
Although the EnterLeaveListener is missing a dependency.
Is it moved or is there a inbuilt way to disabling introspection?

Joe McBride
@joemcbride
@srs6814 I’m not aware of a built-in way to disable introspection, but one way to do it would be to add a validation rule that checked the document for the introspection elements, which would stop the query from executing.

@ShawnAbshire Another way to do it would be to provide your own IGraphQLExecuter<TSchema>, and override the GetOptions method. You can inherit from DefaultGraphQLExecuter<TSchema>.

https://github.com/graphql-dotnet/server/blob/master/src/Core/DefaultGraphQLExecuter.cs

Joe McBride
@joemcbride
@srs6814 Sorry, I didn’t read the linked issue … yes the validation rules have been updated, getting an updated example.
Joe McBride
@joemcbride
srs6814
@srs6814
Thank you @joemcbride
Really appreciate it
ShawnAbshire
@ShawnAbshire
@joemcbride That's actually exactly what I ended up doing after digging deeper into the solution! Thanks!
psinghms
@psinghms
Is there any example to dynamically add the queryType instead of predefining it via classes. I have a requirement where tables keeps getting created and I want to read the table schema and create the querytype object dynamically further exposing predefined mutation. Any help would be appreciated.
Oleg26Dev
@Oleg26Dev
Why I do not receive a real object? There is my question graphql-dotnet/graphql-client#362
Dino
@DinoSourcesRex
Hey everyone. I am updating an old project which uses ExposeExceptions when setting up the middleware but as of 5.0.# this has been removed. Does anyone have any docs on this? My google -ing ability is failing me here and I'm not sure what the appropriate course of action is to complete my migration.
        services.AddGraphQL(options =>
                {
                    options.EnableMetrics = false;
                    options.ExposeExceptions = _hostingEnvironment.IsDevelopment();
                })
Dino
@DinoSourcesRex
Ah-ha. Looks like it was moved to AddGraphQL().AddErrorInfoProvider().
Mario Adam
@i-dentify
Hi - given a QueryArgument with a GraphType that has a ListGraphType as a field. How can I enforce, that the ListGraphType must contain at least one value?
Sean Harding
@optimizasean
If I add in authorization in GraphQL and in a request they ask for a field which is not authorized for them, should the request return an error or should it return all fields except for that one? (or in that case put values into that field (null/0/""/"Not Authorized")?
[Example: ^] ask for Users { name, email, password }, am not allowed to see password.
If you are supposed to fail the whole request and provide no data, then maybe I need to look into how one goes about dynamically building queries based on authorization status which doesn't seem like an ideal solution...
gubzoid
@gubzoid
Could someone help me in figuring out how to deprecate an argument, in this case "userId" given this query.
Field<UserSkillsProfileType, UserSkillsProfileResponse>()
                .Name("userSkillsProfile")
                .Description("Get user skills domain profile information")
                .Argument<NonNullGraphType<IntGraphType>>("userId", "user identifier")
                .ResolveAsync(ctx =>
                {
                    var userId = ctx.GetArgument<int>("userId");
                    return userSkillsService.GetByUserId(userId);
                });
ddelapasse2
@ddelapasse2
Hi All! We cannot get our code updated to use V4. Some kind of issue with Newtonsoft's JObject missing the ToInputs method and then we spiraled from there. Anyone know of a working sample project using .net core that we could use for hints?
Joe McBride
@joemcbride
@ddelapasse2 ToInputs is an extension in the GraphQL.NewtonSoftJson Nuget https://github.com/graphql-dotnet/graphql-dotnet/blob/42b83821cbf224848531723d9689df6a2ae30c7c/src/GraphQL.NewtonsoftJson/StringExtensions.cs#L29 You have that nuget package?
Are you upgrading to v4 from 2.4?
Joe McBride
@joemcbride
Link to the 3.x upgrade docs about serialization changes. https://graphql-dotnet.github.io/docs/migrations/migration3#json-parsing-and-serialization
ddelapasse2
@ddelapasse2
image.png
ddelapasse2
@ddelapasse2
We're trying to go from the preview to 3.0 to 4.6. Made it to 3.0, but can't get any further. My string extension method doesn't have ToInputs anymore (it was there prior). I will check the document. Thanks!
Joe McBride
@joemcbride
Right … part of the 3.0 upgrade are new separate serialization nuget packages, one for NewtonSoft and one for System.Text.Json. Need to add one of those to your project.
cheaze
@cheaze
Hi, I am using GraphQL 2.4.0 with GraphQL.Relay 0.5.0. I have been using it successfully for all my needs with serving data to a Gatsby build engine. It's been great.
I have been making use of the ConnectionType in the Relay package.
I need to build a new feature for searching for properties (houses/flats etc), which will return Connection<PropertyType> and take in arguments as parameters, this is all fine and works.
However, in addition to the paged results being returned, my search also needs to be able to return the "facets" of the search.
E.g. Let's say the search returns 40 properties. The facets may say of the 40 results we have "25 houses, 10 flats & 5 bungalows" or "10 properties have 2 bedrooms, 25 have 3 bedrooms, & 5 have 4 bedrooms."
I have this List<Facets> created and returned by the search method and it's ready to go. It's not really part of the property data, it's additional data about the search.
Is there a way to somehow add extra Fields to the Connection? I'd be happy to add this into the PageInfo or as new object on the Connection?
Is this possible, I have tried various things (extending the PageInfoType in my project) but I am struggling to get this going? Is there something clever I am missing?
Thanks!
cpang2
@cpang2
hi, i am trying to use schema first approach for graphql. based on the example given here https://graphql-dotnet.github.io/docs/getting-started/introduction/,
say GetHero returns the results from the repository class. How do I pass in the repository (eg, DatabaseRepository which implements IDatabaseRepository interface) using dependency injection? I cannot seem to find example for schema first approach. Your help is appreciated.
Joe McBride
@joemcbride

@cpang2 You can use constructor injection. So just pass the dependency to the constructor of the Graph Type class.

public class Query
{
    private readonly IDroidRepo _droidRepo;

    public Query(IDroidRepo droidRepo)
    {
        _droidRepo = droidRepo;
    }

    [GraphQLMetadata("droid")]
    public Task<Droid> GetDroid(string id)
    {
        return _droidRepo.GetDroidByIdAsync(id);
    }
}

Make sure your dependency (IDroidRepo in this case) is registered with your DI Container, and the DI container is configured on the Schema.

Joe McBride
@joemcbride
This is what it looks like to register the ServiceProvder with the Schema in schema first in ASP.NET Core.
services.AddTransient<ISchema>(s =>
{
    return Schema.For(@"
        type Droid {
            id: ID!
            name: String!
        }
        type Query {
            droid(id: ID!): Droid
        }
    ", _ =>
    {
        _.ServiceProvider = s;
        _.Types.Include<Query>();
    });
});

This example also shows how to use Authorization, as well as shows how you could have the Schema syntax paired with the .NET class.

graphql-dotnet/examples#66
https://github.com/graphql-dotnet/examples/pull/66/files#diff-ece58d1582d42b863aaa59e00ec82ea7c82d381729cd1eb72120416e2ee4aa52

     [GraphQLMetadata("Query")]
     [GraphTypeMetadata(@"
         extend type Query {
             viewer: User
         }
     ")]
     public class QueryType
     {
         [GraphQLAuthorize("CustomRequirement")]
         public User Viewer()
         {
             return new User { Id = 1, Name = "Quinn" };
         }
     }
cpang2
@cpang2

@joemcbride , is that all is needed in startup class? Do I need the following to add Query in services? Would be great if you can provide a complete solution including Startup class. Thanks!

services.AddSingleton(new Query());

Kevin McGill
@kmcgill88_gitlab
image.png
Hello all, I am using schema first and have hooked graphql up to an azure function. I ran into a strange issue where anytime I pass parameterized variables i get the above error (or similar). Could anyone please point me in the right direction?
image.png
Strange enough if I just hard code the ID into the query things works as I'd expect.
Ashish Nakil
@anakil-mdsol
Hi, do we have any references of schema first approach. Appreciate your help.