コード例 #1
0
        private async Task <IQueryDescriptor> LoadAsync(
            string name, string fileName, DocumentNode document)
        {
            OperationDefinitionNode operation =
                document.Definitions.OfType <OperationDefinitionNode>()
                .FirstOrDefault(t => t.Name is null);

            if (operation != null)
            {
                throw new GeneratorException(HCErrorBuilder.New()
                                             .SetMessage("All operations have to have a name in order " +
                                                         "to work with Strawberry Shake. Check the specified " +
                                                         "operation and give it a name, then retry generating " +
                                                         "the client.")
                                             .SetCode("OPERATION_NO_NAME")
                                             .AddLocation(operation)
                                             .SetExtension("fileName", fileName)
                                             .Build());
            }

            DocumentNode rewritten = AddTypeNameQueryRewriter.Rewrite(document);

            byte[] rewrittenBuffer;

            var serializer = new QuerySyntaxSerializer(false);

            using (var stream = new MemoryStream())
            {
                using (var sw = new StreamWriter(stream))
                {
                    using (var writer = new DocumentWriter(sw))
                    {
                        serializer.Visit(rewritten, writer);
                    }
                }

                await stream.FlushAsync().ConfigureAwait(false);

                rewrittenBuffer = stream.ToArray();
            }

            string hash = _hashProvider.ComputeHash(rewrittenBuffer);

            var descriptor = new QueryDescriptor(
                name,
                _namespace,
                _hashProvider.Name,
                hash,
                rewrittenBuffer,
                document);

            _descriptors.Add(descriptor);
            return(descriptor);
        }
コード例 #2
0
 public GraphQLException(string message)
     : this(ErrorBuilder.New().SetMessage(message).Build())
 {
 }