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
Sean Harding
@optimizasean
@joemcbride that is a good sample! I like that setup, is there a specific benefit to using a gateway service instead of having one graphql endpoint? (no microservice backing)
minecraftchest1
@minecraftchest1:matrix.org
[m]
Hello.
I am wondering if there is an easy way to use this with an asp.net core web api project.
minecraftchest1
@minecraftchest1:matrix.org
[m]
Hello?
Joe McBride
@joemcbride
@minecraftchest1:matrix.org Yes you can. The core GraphQL library is server agnostic. It can be used with any .NET application.

This example using Middleware, but you can just as easily use a Controller if you wish.

https://github.com/graphql-dotnet/examples/tree/master/src/AspNetCoreCustom

Joe McBride
@joemcbride
@optimizasean There are a few reasons. One is to enable independent deployments of multiple backend services. When you have larger teams, each team can independently deploy their owned service. Another reason would be to have a central place for caching, authentication/authorization, or transforming the request (for instance, using a diffrent JWT for internal services vs. a “public” jwt for the gateway). If you have a small team without some of those requirements, it can be a lot more overhead.
Sean Harding
@optimizasean
Thanks @joemcbride , that makes a whole lot of sense! Gives me a new perspective on the use of gateway services.
Got some thinking to do on some architectural decisions to try things out
sanichol
@sanichol
Hey all, I am having some issues understanding the best way to validate a form input mutation. I saw the docs on field middleware but I'm still having trouble setting anything up :( Any help is super appreciated!
Sean Harding
@optimizasean
Originally I wrote the validations into the mutations, but then to clean it up I was writing validators using FluentValidation. That field middleware seems like a much better option, hadn't heard of it until now.
sachindwivediit
@sachindwivediit
How to validate date type argument if i pass something wrong instead of date like in below query
invoice(startDate:"2021/05-01"){
invoiceNumber
}
currently i am getting graphql error like this "errors": [
{
"message": "Argument 'startDate' has invalid value. Expected type 'Date', found \"2021/05-01\".",
Martin Ekman
@Martin-Ekman
@sachindwivediit I don't really get the question. You are asking for validation, and that's exactly what have happened here. The date has been validated to not valid, and you get an error in your request.
If you mean you want it to pass the validation, you have to pass it as a string then validate it in the resolver instead.
sachindwivediit
@sachindwivediit

I means how i can create custom validation for date type argument..

for eg : query {
Invoice( startDate: "2021/05=06" endDate: "2021-05-15")
{invoice number}

In this query , i am trying to filter invoice based on startdate and enddate but i have wrong format so it should validate with my custom message ..but currently i am unable to achieve

sachindwivediit
@sachindwivediit
@Martin-Ekman in short how we could validate date type argument at the time of executing the graphql query
Sean Harding
@optimizasean
@sachindwivediit Are you trying to validate the data structure itself (date, string, int), the format of the data (like date types and standards M/D/Y, D/M/Y, MMM D YYY, ...), or the data itself (name not empty, int between x and y, string is all caps)?
I personally am looking for how to validate the data to make sure results are within expected parameters. I don't think the field middleware is the right place for this but I am not sure...
Matthew Abbott
@Antaris
Hi all, I'm building out a read-only GraphQL API on top of a dynamic CMS. Within the CMS, widgets carry dynamic configurations, which I would like to represent in the schema as an arbitrary JSON value assigned to a field. I've looked over a number of issues, and it's not immediately clear if this scenario is supported?
ShawnAbshire
@ShawnAbshire

Hello - Is there a way to map the inputtype to a different propery on the entity (dto)

For instance in my InputGraphType i've got grantType but on the entity it's ClientGrantType.... is there a way to map the input type => the correct one kind of how fields on ObjectGraphTypes do it?

ShawnAbshire
@ShawnAbshire
Nevermind, it seems 4.0 added a ParseDictionary over ride that I can take advantage of.
saurav kumar bhagat
@saurav-bhagat
Hey, I have a situation where I'm getting data from an external WebSocket source(A) and publishing that over a graphql Subscription websocket to the client.
Currently, when my graphql server disconnects with the external WebSocket source for any reason, the client subscription WebSocket is still open. I couldn't disconnect the user/client from graphql subscription WebSocket.
How can I achieve this?
sachindwivediit
@sachindwivediit
I am writing unit test for graphql query and there mock data i keep in json file and then in the unit test case i am mentioning query and expected data ..but i am facing one issue that my timestamp date in automatically converted into other value for eq : "invoiceDate": "2002-05-19T22:00:00+00:00" is the expected date but its automatically converted and compared with "invoiceDate": "2002-05-20T03:30:00+05:30" ....Any idea how we can keep them universal
Cezary Walenciuk
@PanNiebieski
Cezary Walenciuk
@PanNiebieski
Never mind, I already resolve this
Oleg26Dev
@Oleg26Dev
I develop ASP.NET Core server with Grahql dotnet and net core client. Query and Mutation work fine on client and the server process them. But Subscription does not work. When I try to subscribe I receive the exception:
There is my client function:
    static async Task SubTest()
    {
        Console.WriteLine("configuring client ...");
        var opt = new GraphQLHttpClientOptions { UseWebSocketForQueriesAndMutations = true };

        var uri = new Uri(serviceURL);
        var graphQLOptions = new GraphQLHttpClientOptions
        {
            EndPoint = uri,
            UseWebSocketForQueriesAndMutations = true,
            HttpMessageHandler = new NativeMessageHandler(),
        };
        using (var client = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer()))
        {

            Console.WriteLine("subscribing to message stream ...");

            var subscriptions = new CompositeDisposable();

            subscriptions.Add(client.WebSocketReceiveErrors.Subscribe(e =>
            {
                if (e is WebSocketException we)
                    Console.WriteLine($"WebSocketException: {we.Message} (WebSocketError {we.WebSocketErrorCode}, ErrorCode {we.ErrorCode}, NativeErrorCode {we.NativeErrorCode}");
                else
                    Console.WriteLine($"Exception in websocket receive stream: {e.ToString()}");
            }));

            subscriptions.Add(CreateSubscription("1", client));
            await Task.Delay(200);
        }
        Console.WriteLine("client disposed ...");
    }
private static IDisposable CreateSubscription(string id, GraphQLHttpClient client)
{
var usdbActionAddedRequest = new GraphQLRequest
{
Query = @"
subscription {
dbActionAdded{
name
id
}
}"
};
IObservable<GraphQLResponse<DbActionAddedSubscriptionResult>> subscriptionStream
= client.CreateSubscriptionStream<DbActionAddedSubscriptionResult>(usdbActionAddedRequest);
var stream = client.CreateSubscriptionStream<DbActionAddedSubscriptionResult>(
usdbActionAddedRequest);
return stream.Subscribe(
response => Console.WriteLine($"{id}: new message from \"{response.Data.DbActionAdded.Name}\": {response.Data.DbActionAdded.Id}"),
exception => Console.WriteLine($"{id}: message subscription stream failed: {exception}"),
() => Console.WriteLine($"{id}: message subscription stream completed"));
}
I receive the exception:
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!