2

The graphQLClient package: https://github.com/graphql-dotnet/graphql-client

Integrating queries and mutations through the GraphQL client package was pretty easy. Since I was able to add authentication through a custom HttpMessageHandler and I was then able to use the AWSV4Signer to sign the request before it is sent. The problem which I am currently facing with subscriptions is that this message handler is not being invoked for the requests sent through the subscriptions. Which makes sense since it uses WebSockets and not Http. My question is whether I can use something like the HttpMessageHandler but for web sockets in order to sign the requests(more generally, edit them before they are sent) or I will just have to build and send the web socket requests from scratch like in this post: AWS Appsync implementation using GraphQL-client library in .Net

The code for sending a mutation or query:

var graphQlRequest = new GraphQLRequest
        {
            Query = mutation
        };

        var graphQlClient = new GraphQLHttpClient(new GraphQLHttpClientOptions
        {
            EndPoint = new Uri(endpoint),
            HttpMessageHandler = new AWSMessageHandler(accessKey, secretKey)
        },
        new NewtonsoftJsonSerializer());
        graphQlClient.HttpClient.DefaultRequestHeaders.Add("x-amz-security-token", sessionToken);

        var respoonse = await graphQlClient.SendMutationAsync<T>(graphQlRequest);

The AWSMessageHandler is a custom class I built, It simply signs the HttpRequestMessage before it is sent.

Matan
  • 65
  • 1
  • 6

0 Answers0