@Test public void testBuild() { DataFetcher fetcher = mock(DataFetcher.class); ModelBuilder builder = new ModelBuilder(dictionary, new NonEntityDictionary(), fetcher); GraphQLSchema schema = builder.build(); assertNotEquals(schema.getType(AUTHOR), null); assertNotEquals(schema.getType(BOOK), null); assertNotEquals(schema.getType(AUTHOR_INPUT), null); assertNotEquals(schema.getType(BOOK_INPUT), null); assertNotEquals(schema.getType("_root"), null); GraphQLObjectType bookType = getConnectedType((GraphQLObjectType) schema.getType(BOOK), null); GraphQLObjectType authorType = getConnectedType((GraphQLObjectType) schema.getType(AUTHOR), null); assertTrue(bookType.getFieldDefinition(TITLE).getType().equals(Scalars.GraphQLString)); assertTrue(bookType.getFieldDefinition(GENRE).getType().equals(Scalars.GraphQLString)); assertTrue(bookType.getFieldDefinition(LANGUAGE).getType().equals(Scalars.GraphQLString)); assertTrue(bookType.getFieldDefinition(PUBLISH_DATE).getType().equals(Scalars.GraphQLLong)); assertTrue(bookType.getFieldDefinition(WEIGHT_LBS).getType().equals(Scalars.GraphQLBigDecimal)); GraphQLObjectType addressType = (GraphQLObjectType) authorType.getFieldDefinition("homeAddress").getType(); assertTrue(addressType.getFieldDefinition("street1").getType().equals(Scalars.GraphQLString)); assertTrue(addressType.getFieldDefinition("street2").getType().equals(Scalars.GraphQLString)); GraphQLObjectType authorsType = (GraphQLObjectType) bookType.getFieldDefinition(AUTHORS).getType(); GraphQLObjectType authorsNodeType = getConnectedType(authorsType, null); assertTrue(authorsNodeType.equals(authorType)); assertTrue(authorType.getFieldDefinition(NAME).getType().equals(Scalars.GraphQLString)); assertTrue(validateEnum(Author.AuthorType.class, (GraphQLEnumType) authorType.getFieldDefinition(TYPE).getType())); GraphQLObjectType booksNodeType = (GraphQLObjectType) authorType.getFieldDefinition(BOOKS).getType(); assertFalse(booksNodeType.equals(bookType)); GraphQLInputObjectType bookInputType = (GraphQLInputObjectType) schema.getType(BOOK_INPUT); GraphQLInputObjectType authorInputType = (GraphQLInputObjectType) schema.getType(AUTHOR_INPUT); assertTrue(bookInputType.getField(TITLE).getType().equals(Scalars.GraphQLString)); assertTrue(bookInputType.getField(GENRE).getType().equals(Scalars.GraphQLString)); assertTrue(bookInputType.getField(LANGUAGE).getType().equals(Scalars.GraphQLString)); assertTrue(bookInputType.getField(PUBLISH_DATE).getType().equals(Scalars.GraphQLLong)); GraphQLList authorsInputType = (GraphQLList) bookInputType.getField(AUTHORS).getType(); assertTrue(authorsInputType.getWrappedType().equals(authorInputType)); assertTrue(authorInputType.getField(NAME).getType().equals(Scalars.GraphQLString)); GraphQLList booksInputType = (GraphQLList) authorInputType.getField(BOOKS).getType(); assertTrue(booksInputType.getWrappedType().equals(bookInputType)); }
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; }