GraphqlHttpClient | Graphql http client for .net | REST library
kandi X-RAY | GraphqlHttpClient Summary
kandi X-RAY | GraphqlHttpClient Summary
Very simple Graphql http client for .net by taking advantage of IHttpClientFactory from latest version of .net core and standard. The response object has Data, status code, response time, error message (if any) properties which will be helpful when you interpret the result. There is an extension method available to add Graphql client with inbuilt IoC container. If you want to set base url and time out at the time of configuration, it can be achieved with the below code.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of GraphqlHttpClient
GraphqlHttpClient Key Features
GraphqlHttpClient Examples and Code Snippets
Community Discussions
Trending Discussions on GraphqlHttpClient
QUESTION
I have added a few classes to send requests and handle responses from an external GraphQL web API, which use the GraphQL package from NuGet as well as HttpClient to connect to the API. The classes live in one project of my solution ("providers"). I have also added Test classes and methods to test the functionality of the service classes. The Tests all work as expected - results come back and they match the same queries made in Postman. Having success with the tests, I added references to the service classes to the main project which is an MVC web application in order to supplement user search capabilities - so calling a method from the same project as the Api helper classes within a controller in the MVC application. This is when I started having issues.
As an aside I did not have to add any of the GraphQL packages to the Test project, and it was able to work fine by just referencing the provider project that contains the api helper class. So it seems a bit like overkill in the first place that I had to add all that to the MVC project.
Initially, I was getting errors such as "ReadAsAsync doesn't exist" (this is a method of the System.Net.Http.HttpContent class I think?). This method was used in other classes that consume other external web services using HttpClient in the same project. In fact the method that was failing was nearly identical to ones in other classes that had been working for years at this point. So I thought it was strange it stopped working at this time. I eventually concluded it had something to do with all the dependencies added by adding the GraphQL nuget packages to the "providers" project.
I then added those same GraphQL packages to the MVC project to see if that resolved the issue. This added some issues where it couldn't find some System.IO libraries. I had seen this before in another project where I had to update the .NET version and the solution in that case was to remove the offending dependentAssembly entries in the web.config file. I did that here. Now, I load the web application in debug mode, and can click through to the page where the controller action to search using the new API class is located. The original search actions still work - I am able to get results using them. But the new API method does not. It does not throw an exception. It does not return results. The execution simply stops or seems to stop after the call to the API happens. The GraphQLHttpClient.SendQueryAsync just never comes back. It could just be that I'm not waiting long enough, but I gave it 10 minutes at one point for a query that runs in seconds in the test project, and also in seconds in postman. The application remains operational, though. I can still use other functions of the site after clicking on this.
I guess the question is - how can I find out what the problem is here? Or correct it in some way? I'm currently trying removing different dependentAssembly entries in the MVC project but that isn't really working out very well so far. Some of those entries are needed by the application. But not all of them.
** UPDATE ** I was able to work with some people on another site to resolve the issue. Basically I was calling:
...ANSWER
Answered 2021-Dec-17 at 20:45The solution to this issue was to not try to make an asynchronous process completely synchronous. I changed the whole code pathway to be asynchronous.
QUESTION
I tried to write mutation but it gives me error.
as {"errors":[{"message":"Syntax Error: Expected $, found Name \"objects\"","locations":[{"line":2,"column":27}],"extensions":{"code":"GRAPHQL_PARSE_FAILED"}}]}
The code I wrote is this.
ANSWER
Answered 2021-Jun-06 at 14:15The problem with the example is the data type which is written that is hard to follow PersonAndFilms($id: ID)
now ID is a data type so I was assuming that it was just a variable name declared that's why I was in confusion.
So I had written it as query insert_users(objects: { name: $name, rocket: $rocket })
which was not understandable for GraphQL as it requires Data Type, so I re-writed my query as below.
QUESTION
Is it possible to send graphQL queries with the standard httpclient in .NET core?
When I try to send my query with a client.post I get "Expected { or [ as first syntax token."
How can I send GraphQL queries with a httpclient. Without having to use a library (like GraphQLHttpClient etc..)
...ANSWER
Answered 2021-Feb-26 at 14:54Got it: Just add "query" as a json object. Like this:
QUESTION
I am having a problem similar to this. I have updated my GraphQLHttpClient and now I need to supply an extra parameter, solution give is:
...ANSWER
Answered 2020-Jul-03 at 14:42Your first solution correctly tries to use NewtonsoftJsonSerializer
which is an implementation of IGraphQLWebsocketJsonSerializer
to use Newtonsoft.
Your second correctly uses a constructor which takes it, but you have changed it to be Newtonsoft.Json.JsonSerializer
which is not an implementation of IGraphQLWebsocketJsonSerializer
.
What you want is the second one, but with the right type of IGraphQLWebsocketJsonSerializer
:
QUESTION
I am trying to implement an app sync subscription similar to this python example but in .net https://aws.amazon.com/blogs/mobile/appsync-websockets-python/
I started this using the nuget package GraphQL.Client https://www.nuget.org/packages/GraphQL.Client The execution of Query/Mutation is working fine like given in the readme of https://github.com/graphql-dotnet/graphql-client But subscription is not working.
My code using the GraphQL.Client:
...ANSWER
Answered 2020-Jun-02 at 03:01Nuget won't work out of the box with AppSync subscriptions, so you will need to write your own client code for that, like you attempted in the second (non-nuget) example.
Now, for the second example, take a second look at the python example referenced in your question. There are several steps that are not included in your code. I will enumerate the required steps and try to port them to C# from the python code (note that I don't have a C# environment at hand so there might be syntax errors, but this code should be pretty close to what you need)
Step 0 - AppSync EndpointsAssume the result of invoking aws appsync get-graphql-api --api-id example123456
for your API is:
QUESTION
using var graphQLClient = new GraphQLHttpClient(local, new NewtonsoftJsonSerializer());
var request = new GraphQLRequest{...}
var graphQLResponse = await graphQLClient.SendQueryAsync(request);
return System.Text.Json.JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true });
...ANSWER
Answered 2020-May-29 at 04:10JsonSerializerOptions jso = new JsonSerializerOptions();
jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
var graphQLResponse = await graphQLClient.SendQueryAsync(request);
return System.Text.Json.JsonSerializer.Serialize(graphQLResponse, jso);
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install GraphqlHttpClient
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page