Search in sources :

Example 6 with TypeDefinitionRegistry

use of graphql.schema.idl.TypeDefinitionRegistry in project timbuctoo by HuygensING.

the class RootQuery method rebuildSchema.

public synchronized GraphQLSchema rebuildSchema() {
    final TypeDefinitionRegistry staticQuery = schemaParser.parse(this.staticQuery);
    if (archetypes != null && !archetypes.isEmpty()) {
        staticQuery.merge(schemaParser.parse(archetypes + "extend type DataSetMetadata {\n" + "  archetypes: Archetypes! @passThrough\n" + "}\n" + "\n"));
    }
    TypeDefinitionRegistry registry = new TypeDefinitionRegistry();
    registry.merge(staticQuery);
    final RuntimeWiring.Builder wiring = RuntimeWiring.newRuntimeWiring();
    wiring.type("Query", builder -> builder.dataFetcher("promotedDataSets", env -> dataSetRepository.getPromotedDataSets().stream().map(DataSetWithDatabase::new).collect(Collectors.toList())).dataFetcher("allDataSets", env -> dataSetRepository.getDataSets().stream().map(DataSetWithDatabase::new).filter(x -> {
        if (x.isPublished()) {
            return true;
        } else {
            ContextData contextData = env.getContext();
            UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck();
            return userPermissionCheck.getPermissions(x.getDataSet().getMetadata()).contains(Permission.READ);
        }
    }).collect(Collectors.toList())).dataFetcher("dataSetMetadata", env -> {
        final String dataSetId = env.getArgument("dataSetId");
        ContextData context = env.getContext();
        final User user = context.getUser().orElse(null);
        Tuple<String, String> splitCombinedId = DataSetMetaData.splitCombinedId(dataSetId);
        return dataSetRepository.getDataSet(user, splitCombinedId.getLeft(), splitCombinedId.getRight()).map(DataSetWithDatabase::new);
    }).dataFetcher("dataSetMetadataList", env -> {
        Stream<DataSetWithDatabase> dataSets = dataSetRepository.getDataSets().stream().map(DataSetWithDatabase::new);
        if (env.getArgument("promotedOnly")) {
            dataSets = dataSets.filter(DataSetWithDatabase::isPromoted);
        }
        if (env.getArgument("publishedOnly")) {
            dataSets = dataSets.filter(DataSetWithDatabase::isPublished);
        }
        return dataSets.filter(x -> {
            ContextData contextData = env.getContext();
            UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck();
            return userPermissionCheck.getPermissions(x.getDataSet().getMetadata()).contains(Permission.READ);
        }).collect(Collectors.toList());
    }).dataFetcher("aboutMe", env -> ((RootData) env.getRoot()).getCurrentUser().orElse(null)).dataFetcher("availableExportMimetypes", env -> supportedFormats.getSupportedMimeTypes().stream().map(MimeTypeDescription::create).collect(Collectors.toList())));
    wiring.type("DataSetMetadata", builder -> builder.dataFetcher("currentImportStatus", env -> {
        DataSetMetaData input = env.getSource();
        Optional<User> currentUser = ((RootData) env.getRoot()).getCurrentUser();
        if (!currentUser.isPresent()) {
            throw new RuntimeException("User is not provided");
        }
        return dataSetRepository.getDataSet(currentUser.get(), input.getOwnerId(), input.getDataSetId()).map(dataSet -> dataSet.getImportManager().getImportStatus());
    }).dataFetcher("dataSetImportStatus", env -> {
        Optional<User> currentUser = ((RootData) env.getRoot()).getCurrentUser();
        if (!currentUser.isPresent()) {
            throw new RuntimeException("User is not provided");
        }
        DataSetMetaData input = env.getSource();
        return dataSetRepository.getDataSet(currentUser.get(), input.getOwnerId(), input.getDataSetId()).map(dataSet -> dataSet.getImportManager().getDataSetImportStatus());
    }).dataFetcher("collectionList", env -> getCollections(env.getSource(), ((ContextData) env.getContext()).getUser())).dataFetcher("collection", env -> {
        String collectionId = (String) env.getArguments().get("collectionId");
        if (collectionId != null && collectionId.endsWith("List")) {
            collectionId = collectionId.substring(0, collectionId.length() - "List".length());
        }
        DataSetMetaData input = env.getSource();
        ContextData context = env.getContext();
        final User user = context.getUser().orElse(null);
        final DataSet dataSet = dataSetRepository.getDataSet(user, input.getOwnerId(), input.getDataSetId()).get();
        final TypeNameStore typeNameStore = dataSet.getTypeNameStore();
        String collectionUri = typeNameStore.makeUri(collectionId);
        if (dataSet.getSchemaStore().getStableTypes() == null || dataSet.getSchemaStore().getStableTypes().get(collectionUri) == null) {
            return null;
        } else {
            return getCollection(dataSet, typeNameStore, dataSet.getSchemaStore().getStableTypes().get(collectionUri));
        }
    }).dataFetcher("dataSetId", env -> ((DataSetMetaData) env.getSource()).getCombinedId()).dataFetcher("dataSetName", env -> ((DataSetMetaData) env.getSource()).getDataSetId()).dataFetcher("ownerId", env -> ((DataSetMetaData) env.getSource()).getOwnerId()));
    wiring.type("CurrentImportStatus", builder -> builder.dataFetcher("elapsedTime", env -> {
        final String timeUnit = env.getArgument("unit");
        return ((ImportStatus) env.getSource()).getElapsedTime(timeUnit);
    }));
    wiring.type("DataSetImportStatus", builder -> builder.dataFetcher("lastImportDuration", env -> {
        final String timeUnit = env.getArgument("unit");
        return ((DataSetImportStatus) env.getSource()).getLastImportDuration(timeUnit);
    }));
    wiring.type("EntryImportStatus", builder -> builder.dataFetcher("elapsedTime", env -> {
        final String timeUnit = env.getArgument("unit");
        return ((EntryImportStatus) env.getSource()).getElapsedTime(timeUnit);
    }));
    wiring.type("CollectionMetadata", builder -> builder.dataFetcher("indexConfig", env -> {
        SubjectReference source = env.getSource();
        final QuadStore qs = source.getDataSet().getQuadStore();
        try (Stream<CursorQuad> quads = qs.getQuads(source.getSubjectUri(), TIM_HASINDEXERCONFIG, Direction.OUT, "")) {
            final Map result = quads.findFirst().map(q -> {
                try {
                    return objectMapper.readValue(q.getObject(), Map.class);
                } catch (IOException e) {
                    LOG.error("Value not a Map", e);
                    return new HashMap<>();
                }
            }).orElse(new HashMap());
            if (!result.containsKey("facet") || !(result.get("facet") instanceof List)) {
                result.put("facet", new ArrayList<>());
            }
            if (!result.containsKey("fullText") || !(result.get("fullText") instanceof List)) {
                result.put("fullText", new ArrayList<>());
            }
            return result;
        }
    }).dataFetcher("viewConfig", new ViewConfigFetcher(objectMapper)));
    wiring.type("AboutMe", builder -> builder.dataFetcher("dataSets", env -> (Iterable) () -> dataSetRepository.getDataSetsWithWriteAccess(env.getSource()).stream().map(DataSetWithDatabase::new).iterator()).dataFetcher("dataSetMetadataList", env -> (Iterable) () -> {
        Stream<DataSetWithDatabase> dataSets = dataSetRepository.getDataSets().stream().map(DataSetWithDatabase::new);
        if (env.getArgument("ownOnly")) {
            String userId = ((ContextData) env.getContext()).getUser().map(u -> "u" + u.getPersistentId()).orElse(null);
            dataSets = dataSets.filter(d -> d.getOwnerId().equals(userId));
        }
        Permission permission = Permission.valueOf(env.getArgument("permission"));
        if (permission != Permission.READ) {
            // Read is implied
            UserPermissionCheck check = ((ContextData) env.getContext()).getUserPermissionCheck();
            dataSets = dataSets.filter(d -> check.getPermissions(d).contains(permission));
        }
        return dataSets.iterator();
    }).dataFetcher("id", env -> ((User) env.getSource()).getPersistentId()).dataFetcher("name", env -> ((User) env.getSource()).getDisplayName()).dataFetcher("personalInfo", env -> "http://example.com").dataFetcher("canCreateDataSet", env -> true));
    wiring.type("Mutation", builder -> builder.dataFetcher("setViewConfig", new ViewConfigMutation(dataSetRepository)).dataFetcher("setSummaryProperties", new SummaryPropsMutation(dataSetRepository)).dataFetcher("setIndexConfig", new IndexConfigMutation(dataSetRepository)).dataFetcher("createDataSet", new CreateDataSetMutation(dataSetRepository)).dataFetcher("deleteDataSet", new DeleteDataSetMutation(dataSetRepository)).dataFetcher("publish", new MakePublicMutation(dataSetRepository)).dataFetcher("extendSchema", new ExtendSchemaMutation(dataSetRepository)).dataFetcher("setDataSetMetadata", new DataSetMetadataMutation(dataSetRepository)).dataFetcher("setCollectionMetadata", new CollectionMetadataMutation(dataSetRepository)));
    wiring.wiringFactory(wiringFactory);
    StringBuilder root = new StringBuilder("type DataSets {\n sillyWorkaroundWhenNoDataSetsAreVisible: Boolean\n");
    boolean[] dataSetAvailable = new boolean[] { false };
    dataSetRepository.getDataSets().forEach(dataSet -> {
        final DataSetMetaData dataSetMetaData = dataSet.getMetadata();
        final String name = dataSetMetaData.getCombinedId();
        Map<String, Type> types = dataSet.getSchemaStore().getStableTypes();
        Map<String, List<ExplicitField>> customSchema = dataSet.getCustomSchema();
        final Map<String, Type> customTypes = new HashMap<>();
        for (Map.Entry<String, List<ExplicitField>> entry : customSchema.entrySet()) {
            ExplicitType explicitType = new ExplicitType(entry.getKey(), entry.getValue());
            customTypes.put(entry.getKey(), explicitType.convertToType());
        }
        Map<String, Type> mergedTypes;
        MergeSchemas mergeSchemas = new MergeSchemas();
        mergedTypes = mergeSchemas.mergeSchema(types, customTypes);
        types = mergedTypes;
        if (types != null) {
            dataSetAvailable[0] = true;
            root.append("  ").append(name).append(":").append(name).append(" @dataSet(userId:\"").append(dataSetMetaData.getOwnerId()).append("\", dataSetId:\"").append(dataSetMetaData.getDataSetId()).append("\")\n");
            wiring.type(name, c -> c.dataFetcher("metadata", env -> new DataSetWithDatabase(dataSet)));
            final String schema = typeGenerator.makeGraphQlTypes(name, types, dataSet.getTypeNameStore());
            staticQuery.merge(schemaParser.parse(schema));
        }
    });
    root.append("}\n\nextend type Query {\n  #The actual dataSets\n  dataSets: DataSets @passThrough\n}\n\n");
    if (dataSetAvailable[0]) {
        staticQuery.merge(schemaParser.parse(root.toString()));
    }
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    return schemaGenerator.makeExecutableSchema(staticQuery, wiring.build());
}
Also used : CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) ImmutableProperty(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableProperty) ExplicitType(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitType) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) MakePublicMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MakePublicMutation) LoggerFactory(org.slf4j.LoggerFactory) ExtendSchemaMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ExtendSchemaMutation) DerivedSchemaTypeGenerator(nl.knaw.huygens.timbuctoo.v5.graphql.derivedschema.DerivedSchemaTypeGenerator) DeleteDataSetMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.DeleteDataSetMutation) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) Map(java.util.Map) SummaryPropsMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.SummaryPropsMutation) ImmutableCollectionMetadataList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableCollectionMetadataList) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) ImmutablePropertyList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutablePropertyList) ViewConfigFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ViewConfigFetcher) CreateDataSetMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.CreateDataSetMutation) RootData(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Collectors(java.util.stream.Collectors) Resources.getResource(com.google.common.io.Resources.getResource) List(java.util.List) Stream(java.util.stream.Stream) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) ExplicitField(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitField) Optional(java.util.Optional) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) RdfWiringFactory(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.RdfWiringFactory) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) CollectionMetadata(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.CollectionMetadata) SupportedExportFormats(nl.knaw.huygens.timbuctoo.v5.dropwizard.SupportedExportFormats) CollectionMetadataList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.CollectionMetadataList) DataSetImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetImportStatus) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) HashMap(java.util.HashMap) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) Supplier(java.util.function.Supplier) ContextData(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData) ArrayList(java.util.ArrayList) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) SchemaParser(graphql.schema.idl.SchemaParser) ImmutableStringList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableStringList) GraphQLSchema(graphql.schema.GraphQLSchema) ImmutableCollectionMetadata(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableCollectionMetadata) Charsets(com.google.common.base.Charsets) ViewConfigMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ViewConfigMutation) Logger(org.slf4j.Logger) UserPermissionCheck(nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck) Resources(com.google.common.io.Resources) MimeTypeDescription(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.MimeTypeDescription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MergeSchemas(nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas) Property(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.Property) IOException(java.io.IOException) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) EntryImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.dto.EntryImportStatus) TIM_HASINDEXERCONFIG(nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.TIM_HASINDEXERCONFIG) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) IndexConfigMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.IndexConfigMutation) RuntimeWiring(graphql.schema.idl.RuntimeWiring) DataSetMetadataMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.DataSetMetadataMutation) CollectionMetadataMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.CollectionMetadataMutation) SchemaGenerator(graphql.schema.idl.SchemaGenerator) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Collections(java.util.Collections) MergeSchemas(nl.knaw.huygens.timbuctoo.v5.graphql.customschema.MergeSchemas) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) HashMap(java.util.HashMap) TypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore) ViewConfigMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ViewConfigMutation) Permission(nl.knaw.huygens.timbuctoo.v5.security.dto.Permission) ContextData(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData) Stream(java.util.stream.Stream) ImmutableCollectionMetadataList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableCollectionMetadataList) ImmutablePropertyList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutablePropertyList) List(java.util.List) CollectionMetadataList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.CollectionMetadataList) ArrayList(java.util.ArrayList) ImmutableStringList(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ImmutableStringList) MakePublicMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MakePublicMutation) ExplicitType(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitType) Optional(java.util.Optional) RootData(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData) IndexConfigMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.IndexConfigMutation) RuntimeWiring(graphql.schema.idl.RuntimeWiring) DataSetWithDatabase(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) Map(java.util.Map) HashMap(java.util.HashMap) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) CollectionMetadataMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.CollectionMetadataMutation) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SubjectReference(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference) DeleteDataSetMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.DeleteDataSetMutation) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) CreateDataSetMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.CreateDataSetMutation) DataSetMetadataMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.DataSetMetadataMutation) ExtendSchemaMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ExtendSchemaMutation) SchemaGenerator(graphql.schema.idl.SchemaGenerator) IOException(java.io.IOException) ViewConfigFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.ViewConfigFetcher) ExplicitType(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.ExplicitType) Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) SummaryPropsMutation(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.SummaryPropsMutation) UserPermissionCheck(nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck)

Example 7 with TypeDefinitionRegistry

use of graphql.schema.idl.TypeDefinitionRegistry in project incubator-skywalking by apache.

the class GraphQLScriptTest method assertScriptFormat.

@Test
public void assertScriptFormat() {
    SchemaParser schemaParser = new SchemaParser();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
    typeRegistry.merge(schemaParser.parse(loadSchema("common.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("trace.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("overview-layer.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("application-layer.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("server-layer.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("service-layer.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("alarm.graphqls")));
    typeRegistry.merge(schemaParser.parse(loadSchema("config.graphqls")));
    RuntimeWiring wiring = buildRuntimeWiring();
    assertTrue(schemaGenerator.makeExecutableSchema(typeRegistry, wiring).getAllTypesAsList().size() > 0);
}
Also used : RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaParser(graphql.schema.idl.SchemaParser) Test(org.junit.Test)

Example 8 with TypeDefinitionRegistry

use of graphql.schema.idl.TypeDefinitionRegistry in project graphql-java by graphql-java.

the class HttpMain method buildStarWarsSchema.

private GraphQLSchema buildStarWarsSchema() {
    // 
    if (starWarsSchema == null) {
        // 
        // 
        // the fetcher of friends uses java-dataloader to make the circular friends fetching
        // more efficient by batching and caching the calls to load Character friends
        // 
        DataFetcher friendsFetcher = environment -> {
            DataLoaderRegistry dataloaderRegistry = asMapGet(environment.getContext(), "dataloaderRegistry");
            DataLoader friendsDataLoader = dataloaderRegistry.getDataLoader("friends");
            List<String> friendIds = asMapGet(environment.getSource(), "friends");
            return friendsDataLoader.loadMany(friendIds);
        };
        // 
        // reads a file that provides the schema types
        // 
        Reader streamReader = loadSchemaFile("starWarsSchemaAnnotated.graphqls");
        TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(streamReader);
        // 
        // the runtime wiring is used to provide the code that backs the
        // logical schema
        // 
        TypeResolver characterTypeResolver = env -> {
            Map<String, Object> obj = (Map<String, Object>) env.getObject();
            String id = (String) obj.get("id");
            GraphQLSchema schema = env.getSchema();
            if (StarWarsData.isHuman(id)) {
                return (GraphQLObjectType) schema.getType("Human");
            } else {
                return (GraphQLObjectType) schema.getType("Droid");
            }
        };
        RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring().type(newTypeWiring("Query").dataFetcher("hero", StarWarsData.getHeroDataFetcher()).dataFetcher("human", StarWarsData.getHumanDataFetcher()).dataFetcher("droid", StarWarsData.getDroidDataFetcher())).type(newTypeWiring("Human").dataFetcher("friends", friendsFetcher)).type(newTypeWiring("Droid").dataFetcher("friends", friendsFetcher)).type(newTypeWiring("Character").typeResolver(characterTypeResolver)).type(newTypeWiring("Episode").enumValues(StarWarsData.getEpisodeResolver())).build();
        // finally combine the logical schema with the physical runtime
        starWarsSchema = new SchemaGenerator().makeExecutableSchema(typeRegistry, wiring);
    }
    return starWarsSchema;
}
Also used : Request(org.eclipse.jetty.server.Request) ExecutionInput.newExecutionInput(graphql.ExecutionInput.newExecutionInput) DataLoaderRegistry(org.dataloader.DataLoaderRegistry) Handler(org.eclipse.jetty.server.Handler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) GraphQL(graphql.GraphQL) ServletException(javax.servlet.ServletException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ExecutionResult(graphql.ExecutionResult) DataLoaderDispatcherInstrumentation(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation) HttpServletRequest(javax.servlet.http.HttpServletRequest) BatchLoader(org.dataloader.BatchLoader) DataLoaderDispatcherInstrumentationOptions.newOptions(graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions.newOptions) SchemaParser(graphql.schema.idl.SchemaParser) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) TracingInstrumentation(graphql.execution.instrumentation.tracing.TracingInstrumentation) TypeResolver(graphql.schema.TypeResolver) Server(org.eclipse.jetty.server.Server) StarWarsData(graphql.StarWarsData) GraphQLObjectType(graphql.schema.GraphQLObjectType) HandlerList(org.eclipse.jetty.server.handler.HandlerList) HttpServletResponse(javax.servlet.http.HttpServletResponse) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) IOException(java.io.IOException) DataLoader(org.dataloader.DataLoader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) TypeRuntimeWiring.newTypeWiring(graphql.schema.idl.TypeRuntimeWiring.newTypeWiring) ExecutionInput(graphql.ExecutionInput) ChainedInstrumentation(graphql.execution.instrumentation.ChainedInstrumentation) List(java.util.List) Instrumentation(graphql.execution.instrumentation.Instrumentation) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) InputStream(java.io.InputStream) TypeResolver(graphql.schema.TypeResolver) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) DataLoader(org.dataloader.DataLoader) RuntimeWiring(graphql.schema.idl.RuntimeWiring) DataLoaderRegistry(org.dataloader.DataLoaderRegistry) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) HandlerList(org.eclipse.jetty.server.handler.HandlerList) List(java.util.List) DataFetcher(graphql.schema.DataFetcher) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with TypeDefinitionRegistry

use of graphql.schema.idl.TypeDefinitionRegistry in project graphql-java by graphql-java.

the class ReadmeExamples method parsedSplitSchemaExample.

void parsedSplitSchemaExample() {
    SchemaParser schemaParser = new SchemaParser();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    File schemaFile1 = loadSchema("starWarsSchemaPart1.graphqls");
    File schemaFile2 = loadSchema("starWarsSchemaPart2.graphqls");
    File schemaFile3 = loadSchema("starWarsSchemaPart3.graphqls");
    TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
    // each compiled registry is merged into the main registry
    typeRegistry.merge(schemaParser.parse(schemaFile1));
    typeRegistry.merge(schemaParser.parse(schemaFile2));
    typeRegistry.merge(schemaParser.parse(schemaFile3));
    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, buildRuntimeWiring());
}
Also used : SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaParser(graphql.schema.idl.SchemaParser) File(java.io.File) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 10 with TypeDefinitionRegistry

use of graphql.schema.idl.TypeDefinitionRegistry in project graphql-java by graphql-java.

the class BatchCompare method buildDataLoaderSchema.

GraphQLSchema buildDataLoaderSchema() {
    Reader streamReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("storesanddepartments.graphqls"));
    TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(streamReader);
    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("shops", BatchCompareDataFetchers.shopsDataFetcher)).type(TypeRuntimeWiring.newTypeWiring("Shop").dataFetcher("departments", BatchCompareDataFetchers.departmentsForShopDataLoaderDataFetcher)).type(TypeRuntimeWiring.newTypeWiring("Department").dataFetcher("products", BatchCompareDataFetchers.productsForDepartmentDataLoaderDataFetcher)).build();
    return new SchemaGenerator().makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
}
Also used : InputStreamReader(java.io.InputStreamReader) TypeRuntimeWiring(graphql.schema.idl.TypeRuntimeWiring) RuntimeWiring(graphql.schema.idl.RuntimeWiring) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SchemaParser(graphql.schema.idl.SchemaParser)

Aggregations

SchemaGenerator (graphql.schema.idl.SchemaGenerator)10 SchemaParser (graphql.schema.idl.SchemaParser)10 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)10 RuntimeWiring (graphql.schema.idl.RuntimeWiring)9 GraphQLSchema (graphql.schema.GraphQLSchema)7 ExecutionResult (graphql.ExecutionResult)4 GraphQL (graphql.GraphQL)4 RuntimeWiring.newRuntimeWiring (graphql.schema.idl.RuntimeWiring.newRuntimeWiring)3 File (java.io.File)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 Reader (java.io.Reader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DataFetcher (graphql.schema.DataFetcher)2 StaticDataFetcher (graphql.schema.StaticDataFetcher)2 TypeRuntimeWiring (graphql.schema.idl.TypeRuntimeWiring)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2