@Test public void testRelationshipParameters() { DataFetcher fetcher = mock(DataFetcher.class); ModelBuilder builder = new ModelBuilder(dictionary, new NonEntityDictionary(), fetcher); GraphQLSchema schema = builder.build(); GraphQLObjectType root = schema.getQueryType(); assertNotNull(root); assertNotNull(root.getFieldDefinition(BOOK)); GraphQLFieldDefinition bookField = root.getFieldDefinition(BOOK); assertNotNull(bookField.getArgument(DATA)); assertNotNull(bookField.getArgument(FILTER)); assertNotNull(bookField.getArgument(SORT)); assertNotNull(bookField.getArgument(FIRST)); assertNotNull(bookField.getArgument(AFTER)); GraphQLObjectType bookType = (GraphQLObjectType) schema.getType("_node__" + BOOK); GraphQLFieldDefinition publisherField = bookType.getFieldDefinition("publisher"); assertNotNull(publisherField.getArgument(DATA)); assertNull(publisherField.getArgument(FILTER)); assertNull(publisherField.getArgument(SORT)); assertNull(publisherField.getArgument(FIRST)); assertNull(publisherField.getArgument(AFTER)); GraphQLFieldDefinition authorField = bookType.getFieldDefinition(AUTHORS); assertNotNull(authorField.getArgument(DATA)); assertNotNull(authorField.getArgument(FILTER)); assertNotNull(authorField.getArgument(SORT)); assertNotNull(authorField.getArgument(FIRST)); assertNotNull(authorField.getArgument(AFTER)); }
public GraphQLSchema build() { Set<Class<?>> allClasses = entityDictionary.getBindings(); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } Set<Class<?>> rootClasses = allClasses.stream().filter(entityDictionary::isRoot).collect(Collectors.toSet()); entityDictionary.walkEntityGraph(rootClasses, this::buildInputObjectStub); resolveInputObjectRelationships(); GraphQLObjectType.Builder root = newObject().name("_root"); for (Class<?> clazz : rootClasses) { String entityName = entityDictionary.getJsonAliasFor(clazz); root.field(newFieldDefinition() .name(entityName) .dataFetcher(dataFetcher) .argument(relationshipOpArg) .argument(idArgument) .argument(filterArgument) .argument(sortArgument) .argument(pageFirstArgument) .argument(pageOffsetArgument) .argument(buildInputObjectArgument(clazz, true)) .type(buildConnectionObject(clazz))); } GraphQLObjectType queryRoot = root.build(); GraphQLObjectType mutationRoot = root.name("_mutation_root").build(); entityDictionary.walkEntityGraph(rootClasses, this::buildConnectionObject); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryRoot) .mutation(mutationRoot) .build(new HashSet<>(CollectionUtils.union( connectionObjectRegistry.values(), inputObjectRegistry.values() ))); return schema; }
ModelBuilder { public GraphQLSchema build() { Set<Class<?>> allClasses = entityDictionary.getBindings(); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } Set<Class<?>> rootClasses = allClasses.stream().filter(entityDictionary::isRoot).collect(Collectors.toSet()); entityDictionary.walkEntityGraph(rootClasses, this::buildInputObjectStub); resolveInputObjectRelationships(); GraphQLObjectType.Builder root = newObject().name("_root"); for (Class<?> clazz : rootClasses) { String entityName = entityDictionary.getJsonAliasFor(clazz); root.field(newFieldDefinition() .name(entityName) .dataFetcher(dataFetcher) .argument(relationshipOpArg) .argument(idArgument) .argument(filterArgument) .argument(sortArgument) .argument(pageFirstArgument) .argument(pageOffsetArgument) .argument(buildInputObjectArgument(clazz, true)) .type(buildConnectionObject(clazz))); } GraphQLObjectType queryRoot = root.build(); GraphQLObjectType mutationRoot = root.name("_mutation_root").build(); entityDictionary.walkEntityGraph(rootClasses, this::buildConnectionObject); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryRoot) .mutation(mutationRoot) .build(new HashSet<>(CollectionUtils.union( connectionObjectRegistry.values(), inputObjectRegistry.values() ))); return schema; } }
ModelBuilder { public GraphQLSchema build() { Set<Class<?>> allClasses = entityDictionary.getBindings(); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } Set<Class<?>> rootClasses = allClasses.stream().filter(entityDictionary::isRoot).collect(Collectors.toSet()); entityDictionary.walkEntityGraph(rootClasses, this::buildInputObjectStub); resolveInputObjectRelationships(); GraphQLObjectType.Builder root = newObject().name("_root"); for (Class<?> clazz : rootClasses) { String entityName = entityDictionary.getJsonAliasFor(clazz); root.field(newFieldDefinition() .name(entityName) .dataFetcher(dataFetcher) .argument(relationshipOpArg) .argument(idArgument) .argument(filterArgument) .argument(sortArgument) .argument(pageFirstArgument) .argument(pageOffsetArgument) .argument(buildInputObjectArgument(clazz, true)) .type(buildConnectionObject(clazz))); } GraphQLObjectType queryRoot = root.build(); GraphQLObjectType mutationRoot = root.name("_mutation_root").build(); entityDictionary.walkEntityGraph(rootClasses, this::buildConnectionObject); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryRoot) .mutation(mutationRoot) .build(new HashSet<>(CollectionUtils.union( connectionObjectRegistry.values(), inputObjectRegistry.values() ))); return schema; } ModelBuilder(EntityDictionary entityDictionary,
                        NonEntityDictionary nonEntityDictionary,
                        DataFetcher dataFetcher); }
ModelBuilder { public GraphQLSchema build() { Set<Class<?>> allClasses = entityDictionary.getBindings(); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } Set<Class<?>> rootClasses = allClasses.stream().filter(entityDictionary::isRoot).collect(Collectors.toSet()); entityDictionary.walkEntityGraph(rootClasses, this::buildInputObjectStub); resolveInputObjectRelationships(); GraphQLObjectType.Builder root = newObject().name("_root"); for (Class<?> clazz : rootClasses) { String entityName = entityDictionary.getJsonAliasFor(clazz); root.field(newFieldDefinition() .name(entityName) .dataFetcher(dataFetcher) .argument(relationshipOpArg) .argument(idArgument) .argument(filterArgument) .argument(sortArgument) .argument(pageFirstArgument) .argument(pageOffsetArgument) .argument(buildInputObjectArgument(clazz, true)) .type(buildConnectionObject(clazz))); } GraphQLObjectType queryRoot = root.build(); GraphQLObjectType mutationRoot = root.name("_mutation_root").build(); entityDictionary.walkEntityGraph(rootClasses, this::buildConnectionObject); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryRoot) .mutation(mutationRoot) .build(new HashSet<>(CollectionUtils.union( connectionObjectRegistry.values(), inputObjectRegistry.values() ))); return schema; } ModelBuilder(EntityDictionary entityDictionary,
                        NonEntityDictionary nonEntityDictionary,
                        DataFetcher dataFetcher); void withExcludedEntities(Set<Class<?>> excludedEntities); GraphQLSchema build(); }
ModelBuilder { public GraphQLSchema build() { Set<Class<?>> allClasses = entityDictionary.getBindings(); if (allClasses.isEmpty()) { throw new IllegalArgumentException("None of the provided classes are exported by Elide"); } Set<Class<?>> rootClasses = allClasses.stream().filter(entityDictionary::isRoot).collect(Collectors.toSet()); entityDictionary.walkEntityGraph(rootClasses, this::buildInputObjectStub); resolveInputObjectRelationships(); GraphQLObjectType.Builder root = newObject().name("_root"); for (Class<?> clazz : rootClasses) { String entityName = entityDictionary.getJsonAliasFor(clazz); root.field(newFieldDefinition() .name(entityName) .dataFetcher(dataFetcher) .argument(relationshipOpArg) .argument(idArgument) .argument(filterArgument) .argument(sortArgument) .argument(pageFirstArgument) .argument(pageOffsetArgument) .argument(buildInputObjectArgument(clazz, true)) .type(buildConnectionObject(clazz))); } GraphQLObjectType queryRoot = root.build(); GraphQLObjectType mutationRoot = root.name("_mutation_root").build(); entityDictionary.walkEntityGraph(rootClasses, this::buildConnectionObject); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryRoot) .mutation(mutationRoot) .build(new HashSet<>(CollectionUtils.union( connectionObjectRegistry.values(), inputObjectRegistry.values() ))); return schema; } ModelBuilder(EntityDictionary entityDictionary,
                        NonEntityDictionary nonEntityDictionary,
                        DataFetcher dataFetcher); void withExcludedEntities(Set<Class<?>> excludedEntities); GraphQLSchema build(); static final String ARGUMENT_DATA; static final String ARGUMENT_INPUT; static final String ARGUMENT_IDS; static final String ARGUMENT_FILTER; static final String ARGUMENT_SORT; static final String ARGUMENT_FIRST; static final String ARGUMENT_AFTER; static final String ARGUMENT_OPERATION; }