Пример #1
0
        private static string SerializeQuery(DocumentNode query)
        {
            var content        = new StringBuilder();
            var documentWriter = new DocumentWriter(new StringWriter(content));
            var serializer     = new QuerySyntaxSerializer();

            serializer.Visit(query, documentWriter);
            return(content.ToString());
        }
Пример #2
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);
        }
Пример #3
0
        private static string SerializeQuery(DocumentNode query)
        {
            var queryText = new StringBuilder();

            using (var stringWriter = new StringWriter(queryText))
            {
                var serializer = new QuerySyntaxSerializer();
                serializer.Visit(query, new DocumentWriter(stringWriter));
            }

            return(queryText.ToString());
        }
Пример #4
0
        private static string SerializeArguments(
            IEnumerable <ArgumentNode> arguments)
        {
            var serializer = new QuerySyntaxSerializer();
            var sb         = new StringBuilder();

            using (var stringWriter = new StringWriter(sb))
            {
                var documentWriter = new DocumentWriter(stringWriter);

                return(string.Join(", ", arguments.Select(t =>
                {
                    sb.Clear();
                    serializer.Visit(t.Value, documentWriter);
                    return t.Name.Value + " = " + sb;
                })));
            }
        }