Пример #1
0
        public static IStitchingBuilder AddSchemaFromHttp(
            this IStitchingBuilder builder,
            NameString name)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            name.EnsureNotEmpty(nameof(name));

            builder.AddSchema(name, s =>
            {
                HttpClient httpClient =
                    s.GetRequiredService <IHttpClientFactory>()
                    .CreateClient(name);

                var request = new HttpQueryRequest
                {
                    Query = _introspectionQuery
                };

                var queryClient = new HttpQueryClient();
                string result   = Task.Factory.StartNew(
                    () => queryClient.FetchStringAsync(request, httpClient))
                                  .Unwrap().GetAwaiter().GetResult();
                return(IntrospectionDeserializer.Deserialize(result));
            });

            return(builder);
        }
Пример #2
0
        public static IStitchingBuilder AddSchemaFromHttp(
            this IStitchingBuilder builder,
            NameString name)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            name.EnsureNotEmpty(nameof(name));

            builder.AddSchema(name, s =>
            {
                HttpClient httpClient =
                    s.GetRequiredService <IHttpClientFactory>()
                    .CreateClient(name);
                return(IntrospectionClient.LoadSchema(httpClient));
            });

            return(builder);
        }
Пример #3
0
        public static IStitchingBuilder AddSchemaFromString(
            this IStitchingBuilder builder,
            NameString name,
            string schema)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (string.IsNullOrEmpty(schema))
            {
                throw new ArgumentException(
                          StitchingResources.Schema_EmptyOrNull,
                          nameof(schema));
            }

            name.EnsureNotEmpty(nameof(name));

            builder.AddSchema(name, s => Parser.Default.Parse(schema));
            return(builder);
        }
Пример #4
0
        public static IStitchingBuilder AddSchemaFromFile(
            this IStitchingBuilder builder,
            NameString name,
            string path)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException(
                          StitchingResources.SchemaFilePath_EmptyOrNull,
                          nameof(path));
            }

            name.EnsureNotEmpty(nameof(name));

            builder.AddSchema(name, s =>
                              Utf8GraphQLParser.Parse(File.ReadAllBytes(path)));
            return(builder);
        }