sahb1239 / sahb.graphqlclient Goto Github PK
View Code? Open in Web Editor NEWQuery HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.
License: MIT License
Query HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.
License: MIT License
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.
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.
Support validating GraphQL models using a specified instrospection query output
This could for example be called in unit tests
Implement a GraphQLException which is thrown when the server is returning any errors, either using errors or using status codes
Rename to SAHB.GraphQL.Client
The querybuilder tries to add a null alias if query is null
For example {query{:field1}}. The expected should have been {query{field1}}
Currently the client does not support directives which is described here.
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.
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?
Add disconnected event on IGraphQLSubscriptionClient such that client apps can be notified if the connection is terminated. Related to #70
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.
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.
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.
(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!
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
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.
For example:
{"query":"query{Hero:hero{Name:name Friends:friends{Name:name}}}"}
Should be:
{"query":"query{hero{name friends{name}}}"}
Already supporting skip and take. First and last is more relevant due to the default on connections and those should therefore be added.
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
An issue for the GraphQLHttpExecutorServerErrorStatusCodeException
Related to #10
Support validating that variableNames has been filled
Just exploring if someone has tried using this library with the Unity Game Engine?
Support distinction between multiple variable names with same name
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"});
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..?
Optimize query generation
Releated to #18
When argument value is a simple type (for example string, boolean or int), inline it instead of using separate variable
Cache for queries
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
Support implementation of introspection query
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.