Ejemplo n.º 1
0
        public static async Task <T> PostAsync <T>(string endpoint, MutationRequest request, string section, CancellationToken?token = null)
        {
            var gqlClient = new GraphQLClient(endpoint, new GraphQLClientOptions {
                MediaType = new MediaTypeHeaderValue("application/json")
            });

            try
            {
                var gqlRequest = new GraphQLRequest
                {
                    Query     = request.Query,
                    Variables = request.Variables
                };

                var gqlResponse = await gqlClient.PostAsync(gqlRequest, token ?? CancellationToken.None);

                if (gqlResponse.Errors?.Length > 0)
                {
                    throw new GraphQLException(gqlResponse.Errors[0]);
                }

                var result = gqlResponse.GetDataFieldAs <T>(section);
                return(result);
            }
            finally
            {
                gqlClient.Dispose();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    client.Dispose();
                }

                disposed = true;
            }
        }