コード例 #1
0
        public override void OnBeforeCreate(
            IDescriptorContext context,
            ISchemaBuilder schemaBuilder)
        {
            var allSchemas = new OrderedDictionary <NameString, DocumentNode>();

            foreach (KeyValuePair <NameString, IRequestExecutor> executor in
                     context.GetRemoteExecutors())
            {
                allSchemas.Add(
                    executor.Key,
                    Utf8GraphQLParser.Parse(executor.Value.Schema.Print()));
            }

            IReadOnlyList <DocumentNode> typeExtensions = context.GetTypeExtensions();

            // merge schemas
            DocumentNode mergedSchema = MergeSchemas(context, allSchemas);

            mergedSchema = AddExtensions(mergedSchema, typeExtensions);
            mergedSchema = RewriteMerged(context, mergedSchema);
            mergedSchema = mergedSchema.RemoveBuiltInTypes();

            VisitMerged(context, mergedSchema);
            MarkExternalFields(schemaBuilder, mergedSchema);
            BuildNameLookup(context, schemaBuilder, mergedSchema, allSchemas.Keys);

            schemaBuilder
            .AddDocument(mergedSchema)
            .AddDirectiveType <DelegateDirectiveType>()
            .AddDirectiveType <ComputedDirectiveType>()
            .AddDirectiveType <SourceDirectiveType>()
            .SetTypeResolver(IsOfTypeFallback);
        }
コード例 #2
0
    public static ISchemaBuilder AddDocument(
        this ISchemaBuilder builder,
        DocumentNode document)
    {
        if (builder is null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        if (document is null)
        {
            throw new ArgumentNullException(nameof(document));
        }

        return(builder.AddDocument(sp => document));
    }
コード例 #3
0
    public static ISchemaBuilder AddDocumentFromString(
        this ISchemaBuilder builder,
        string schema)
    {
        if (builder is null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        if (string.IsNullOrEmpty(schema))
        {
            throw new ArgumentException(
                      TypeResources.SchemaBuilderExtensions_SchemaIsEmpty,
                      nameof(schema));
        }

        return(builder.AddDocument(sp => Utf8GraphQLParser.Parse(schema)));
    }
コード例 #4
0
    public static ISchemaBuilder AddDocumentFromFile(
        this ISchemaBuilder builder,
        string filePath)
    {
        if (builder is null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        if (string.IsNullOrEmpty(filePath))
        {
            throw new ArgumentException(
                      "",
                      nameof(filePath));
        }

        return(builder.AddDocument(sp =>
                                   Utf8GraphQLParser.Parse(
                                       File.ReadAllBytes(filePath))));
    }