Code Monkey home page Code Monkey logo

sahb.graphqlclient's People

Contributors

chelliwell avatar jasonfran avatar rs-anders-agren avatar sahb1239 avatar sungam3r 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  avatar

Watchers

 avatar  avatar  avatar  avatar

sahb.graphqlclient's Issues

Supporting secure websockets

An essential requirement of my system is to use certificate-based TLS security between client and server.
I've been able to achieve this on queries by adding the certificates to a HttpClientHandler, using that to instantiate a HttpClient, then using the overridden GraphQLHttpClient.Default().
However I can't see a similar route for GraphQLSubscriptionWebSocketClient.Default(). One idea is to expose the ClientWebSocket, or at least the Options, from the GraphQLSubscriptionWebSocketClient class. To allow for an equivalent to

        public GraphQLSubscriptionWebSocketClient(IGraphQLFieldBuilder fieldBuilder, IGraphQLQueryGeneratorFromFields queryGenerator, IGraphQLDeserialization deserialization, CancellationToken cancellationToken)
        {
            _cancellationToken = cancellationToken;
            _webSocket.Options.AddSubProtocol("graphql-ws");

            X509CertificateCollection certCollection = new X509CertificateCollection
            {    new X509Certificate2(pfxFile, pfxPassword));   };
            _webSocket.Options.ClientCertificates = certCollection;

            this.fieldBuilder = fieldBuilder;
            this.queryGenerator = queryGenerator;
            this.deserialization = deserialization;
        }

Obviously that itself is the wrong way to do it lol. I just wanted to illustrate the aim, and I've also used this code to check that the basic principle is correct - which it seems to be since it does a wss connection to my server.

I'd be interested to hear your thoughts. Note that I am no expert C# programmer, so there may be a better way to achieve it than simply exposing the ClientWebSocket.

Stack overflow exception when using client.Query<T>

Hi,

I was recently trying to use your library to query a GraphQL Backend.
First off: Thanks for the library, it seems to be the most sophisticated (.net) GraphQL-Client library around. :)

However, when I try to use the generic Query extension method on the client class, I always receive a Stack Overflow exception, both with my custom types, as well as with the types from the examples you have provided.

Using the query builder, on the other hand, works fine.

Option to add default header

Hi,
It would be great if there is an option to add request header to executor class. We were not able to access httpclient object at run since it is declared as private variable.

Validate models

Support validating GraphQL models using a specified instrospection query output

This could for example be called in unit tests

Allow complex arguments for GraphQL Queries

Hi,

currently, the GraphQLQueryArgument class only supports query arguments with simple types.
I would like to be able to include "complex" types in my queries, like this:

IGraphQLHttpClient client = GraphQLHttpClient.Default();

var response = await client.Query<Query>("https://mpjk0plp9.lp.gql.zone/graphql", 
    arguments: new GraphQLQueryArgument("test", new {Id = 1, Identifier = "test"}));

Currently, I have to serialiye an object like this beforehand to fit the signature of the ``GraphQLQueryArgument` constructor:

IGraphQLHttpClient client = GraphQLHttpClient.Default();

var response = await client.Query<Query>("https://mpjk0plp9.lp.gql.zone/graphql", 
    arguments: new GraphQLQueryArgument("test", JsonConvert.SerializeObject(new {Id = 1, Identifier = "test"})));

However, this leads to issues with the generated Json, resulting in:

"variables": {
        "test": "{\"Id\":1, \"Identifier\":\"test\"}"
    }
}

which will not be deserialized correctly.

Suggested fix: Change the type of GraphQLQueryArgument.ArgumentValue to object.

Bug, alias null

The querybuilder tries to add a null alias if query is null

For example {query{:field1}}. The expected should have been {query{field1}}

No upper-case fields

The 'parsing' of query classes etc cannot retain uppercase letters in the names e.g.

public class Query
{
   public CharacterOrPerson Hero { get; set; }
}
...

becomes

{"query":"query{hero{name friends{name}}}"}

not

{"query":"Query{Hero{Name Friends{Name}}}"}

Can this be solved?

Cannot inline argument using attribute

Attributes needs a constant in the constructers and therefore inlineArgument cannot be a Nullable and needs to just be a bool. Also the property is not included in the fields

Websocket connection fields should be lower case

Hi, have just starting exploring this client today, and found an issue with subscriptions: I am using an Apollo server, and it objects (i.e. the connection fails) to 'id'/'type'/'payload' being capitalized in the websocket messages.
If you restore the 'DataContract' stuff in OperationMessages.cs (as per the original from graphql-dotnet/server), then it connects to Apollo successfully.

Generate queries without using C# models

Implement another simple way of generation the GraphQL fields so it's not required to create a class for each query if for example the output is not used. This can typically be the case for mutations if the do not return anything but however takes an argument

Introspection

I realise this is only on the develop branch, but what goals do you have in mind for this?
I have a closed server/client system, but nonetheless it would improve code maintainability if the client could, for example, discover the fields provided by the server's subscriptions and create a 'subscribe' query containing everything - i.e. construct it's own 'wildcard' on the fly. It gets tricky when an object format/name gets changed in the server but you forget to update the client! (A smart client could also perform some confirmation that the server schema matches the query it's planning on doing, and flag up a more informative error if not).
So I wondered how far you'd got with this, and whether you could give me any 'getting started' tips so I could go exploring along the lines of the above scenario?
Thanks.

Use with Unity3D

Just exploring if someone has tried using this library with the Unity Game Engine?

Enum in subscription 'query'

I can add a string argument to a subscription:

        public class MessageSubscription
        {
        [GraphQLArguments("src", "String", "fromSrc", IsRequired = true)]
        public Message subRd { get; set; }
        }

        public class Message
        {
            public string src { get; set; }
            public Record record { get; set; }
        }


        var operation = await graphQLSubscriptionClient.ExecuteOperation<MessageSubscription>(new GraphQLQueryArgument("fromSrc", "SB"));

Gives a query:

"{\"query\":\"subscription subRd{subRd(src:\\\"SB\\\"){src record}}\"}"

Trouble is, the argument actually needs to be an enum:

        public enum RdSrc
        {
            SB,
            XB
        }

for query

"{\"query\":\"subscription subRd{subRd(src:SB){src record}}\"}"```

Is this possible..?

Handling loss of websocket connection

(Me again lol)
An area I'm concerned about is if a subscription websocket gets disconnected - loss of network, server restart etc.
I will be supplying an intermediate library for people to write their own 'as simple as possible' client app for receiving specific subscription messages from my server, and I would prefer not to burden them with reconnection headaches. - i.e. have either my library or [ideally!] SAHB.GraphQLClient deal with retrying on first subscribe, and with reconnecting if the websocket goes down after that.
I see that OnDisconnected() is empty, so maybe it's 'work in progress' - but it's quite a key area for me which would be great to see enhanced.
I appreciate that it might not be an easy one!

Support specifying that a argument only applies to a specific field

Support only applying argument to one field. For example given the following query:
`
public class Query
{
[GraphQLArgumentAttribute("argumentName", "ArgumentType", "variableName")]
public Hero Hero1 { get; set; }

[GraphQLArgumentAttribute("argumentName", "ArgumentType", "variableName")]
public Hero Hero2 { get; set; }
}
`

It should be possible to call the GraphQL query in the following way:
var response = await client.Query<HeroQuery>(arguments: new[] { new GraphQLQueryArgument<HeroQuery>("variableName", "valueToBeSentToHero1", e => e.Hero1), new GraphQLQueryArgument<HeroQuery>("variableName", "valueToBeSentToHero2", e => e.Hero1) });

Related to #51

No warning when adding an argument that is not in the model

Sample code which should give som kind of warning (or exception):

public class SampleQuery
{
   public string Hello { get; set; }
}

await client.Query<SampleQuery>("url", 
   arguments: new GraphQLQueryArgument("helloVariableName", "helloVariableValue"});

Optimization of queries

Try to optimize queries if it's possible, for example using fragments or in some cases if the same query is executed 2 times, only execute it once. This will especially be useful if #10 is implemented.

The performance benefit should however also be considered.

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.