Coder Social home page Coder Social logo

charlesdevandiere / graphql-query-builder-dotnet Goto Github PK

View Code? Open in Web Editor NEW
43.0 43.0 15.0 92 KB

A .NET GraphQL query builder

Home Page: https://charlesdevandiere.github.io/graphql-query-builder-dotnet/

License: MIT License

Batchfile 0.49% C# 99.02% Shell 0.49%
csharp dotnet graphql graphql-query-builder

graphql-query-builder-dotnet's People

Contributors

asiffermann avatar charlesdevandiere avatar miguezs avatar sfiodorov avatar sokolowskip avatar victoriakalinichenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

graphql-query-builder-dotnet's Issues

Nullable arguments

Description

I need to filter a query based on nullable field. Currently I cannot use the query builder to say : { neq: null } because this triggers compiler error CS0828. In order to use the null filtration properly, I've to explicitly replace all occurrences of "null" with null. It would be nice if the builder does this task for me.

Update reference on Newtonsoft.Json to v 12.x.y

Hi guys,

We are happily using GraphQL.Query.Builder to build our queries.
There one minor problem though: the latest release depends on Newtonsoft.Json 11.0.1.
It would be good to upgrade its dependencies to a more recent release, like 12.0.3.

This would save some hassle with bindingRedirect's in exe.config files, as most of the GraphQL.Server 3.x dependencies are now using Newtonsoft.Json 12.0.3.

Kind regards,
Reureu

Query Build with nullable value exception.

I'm trying to create a mutation query that contains an KeyValue property with possible Null value, following we have an example:

Dice.SoldAt is a Nullable<DateTime> that is null at when it is created on api. new Dictionary<string, DateTime?> { {"dice_id", Dice.Id}, {"sold_at", Dice.SoldAt} ... };

And when I try to build my query, I got an null exception.

This is the exception message.

Unsupported Query Parameter, Type Found : System.Collections.Generic.KeyValuePair2[System.String,System.Nullable1[System.DateTime]]

How to create a query which accepts nullable values?

troubles with where and order queries

var query = new Query<Company>("companies", new()
        {
            Formatter = CamelCasePropertyNameFormatter.Format
        })
            .AddField(p => p.Name)
            .AddField(p => p.Sites, sites => 
                sites.AddField(p => p.Name))
            .AddArgument("where", """{name: { contains: "Hallo" }}""")
            .AddArgument("order", """{name: DESC }""")
            .Build();

generated output:

companies(where: "{name: { contains: \"Hallo\" }}", order: "{name: DESC }"){ name sites{ name} }

expected output:

{ companies(where: {name: { contains: "Hallo" }}, order: { name: DESC }) {name, sites {name} } }

just tried out our library but im having trouble generating correct queries with where and order

Add support for formatted query output.

For a project that I'm working on, at runtime, I'm generating GraphQL queries that are displayed to the user. Therefore, I wanted the output of your library to contain appropriate line breaks and indentations. I've accomplished this on my own fork, but wondered if there is any interest in me providing a PR here to add this optional formatting to the output. Thanks.

Missing serializer references?

Is this dead? It looks like you need an instance of IGraphQLWebsocketJsonSerializer to instantiate GraphQLHttpClient but the references lead nowhere.

It is not possible to call AddField when base type is interface

Have interface :

interface IFoo 
{
    string Value {get;set;}
}

Have class

class Foo : IFoo
{
}

Extension code:

public static IQuery<T> WithValue<T>(this IQuery<T> query)
           where T : class, IFoo
        {
            return query.AddField(x => x.Value);
        }

Call :
IQuery<Foo> fields = new Query<Foo>().WithValue()

Expected : value property should be added to query
Observed: ArgumentException fired from QueryOf{T}.cs
Reason: Foo implements the IFoo and not delivered from it. So call to type.IsSubclassOf at line 229 of QueryOf{T} is not valid
Solution: replace call to IsSubclassOf by IsAssignableFrom to allow interface as base type

This PR should fix it: 97eb062

@charlesdevandiere , Could you take a look please?

Is there a problem to create a Query with complex objects in Arguments?

Hi. I'm trying to put and object as param but is throwing an exception when I execute query.Builder().

My object is :

class Filter {
    int parent;
    int amount;
    List<Clauses> clauses;
}

I am trying to create Arguments, but isn't working.

What I've tried:

//creating arguments
var arguments = new Dictionary<string, object>();
arguments.Add("filters", new filters { parent = 1, amount = 15 });

var query = new Query<MyType>("MyTypes")
.AddArguments(arguments)[...]
query.Build();

Throws InvalidDataException: Unsupported Query Parameter

I've tried this too, but without any success.

var query = new Query<MyType>("MyTypes")
.AddArguments(new {filters, arguments)[...]
query.Build();

The same error. How could I create a request using Filter object?

Formatter usage building the Query Arguments

Hi, @charlesdevandiere
First of all, thank you so much, I guess a lot of programming lives were saved thanks to your efforts : )

But I have found a tiny issue with the Argument list building.
The Formatter from Query is not passed to the QueryStringBuilder, so in case if there is an object in the Query Arguments, the Formatter is not applied to the object.

Can I make a pull request to fix that?

A question about mapping expressions

Hi,
i have the following method:
public string GetQuery(params Expression<Func<MyClass, object>>[] properties){}
so i able to use it this way:
GetQuery(x => x.FirstName, x => x.NestedProp.NestedValue);

how can i map the properties array to a valid IQuery?
tried the following:

foreach (var property in properties)
    {
        if (property.Body is MemberExpression)
        {
           // this works for MemberExpressions only
            query.AddField(property);
        }
        else
        {
          // here i have to handle nested expressions "x.NestedProp.NestedValue"
          // i'm not sure how to map the UnaryExpression to the query
        }
    }

can someone please give me a hint?
thanks in advanced

Thanks

Thanks for this project.
I've been looking for such builder for a while.
I've write a GraphQL query builder and the syntax is similar to yours.
I will follow your project with attention.

Build Query and variables separately

Hi! Thanks a lot for this Library! It's a life saver.
However, I'm trying to use the Query with GraphQL.Client.

From the look of it, it seems that the problem is that the variables for the query are passed separated (as parameters) and the parameter definition on the query is just a $token that gets replaced with the variables on the requets to the server.

Do you think its a good idea to implement the builder in a way that it can generate 3 values?:

  • FullQuery (the current output of Build())
  • Query (the query with the replacement tokens instead of the values)
  • Arguments: The actual object with the arguments

I could start working on something like this, but im not sure if you might have a way to use the queries on GraophQL.Client without this change.

Cheers!

Mutation Query

Hi charles,
how can send object parameter in C# like entity:{test:"",test1:""}.

Thanks
Dharuman N

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.