use of org.dotwebstack.framework.core.model.Schema in project dotwebstack-framework by dotwebstack.
the class ModelConfiguration method schema.
@Bean
Schema schema(@Value("${dotwebstack.config:dotwebstack.yaml}") String configFile, List<SchemaValidator> validators) {
var objectMapper = createObjectMapper();
Schema schema = new SchemaReader(objectMapper).read(configFile);
validateSchemaFields(configFile, schema);
backendModule.init(schema.getObjectTypes());
validators.forEach(validator -> validator.validate(schema));
return schema;
}
use of org.dotwebstack.framework.core.model.Schema in project dotwebstack-framework by dotwebstack.
the class FieldPathHelperTest method createObjectFieldPath_returnsListOfObjectField_forPath.
@Test
void createObjectFieldPath_returnsListOfObjectField_forPath() {
Schema schema = new Schema();
TestObjectType objectTypeFoo = createFooObjectType();
TestObjectType objectTypeBar = createBarObjectType();
TestObjectType objectTypeBaz = createBazObjectType();
objectTypeFoo.getField("bar").setTargetType(objectTypeBar);
schema.setObjectTypes(Map.of("Foo", objectTypeFoo, "Bar", objectTypeBar, "Baz", objectTypeBaz));
var path = "bar.baz";
List<ObjectField> result = createFieldPath(objectTypeFoo, path);
assertThat(result.size(), is(2));
assertThat(result.get(0).getName(), is("bar"));
assertThat(result.get(1).getName(), is("baz"));
}
use of org.dotwebstack.framework.core.model.Schema in project dotwebstack-framework by dotwebstack.
the class ModelHelperTest method getObjectType_throwException_forNonGraphQlObjectType.
@Test
void getObjectType_throwException_forNonGraphQlObjectType() {
Schema schema = new Schema();
ObjectType<?> objectType = new TestObjectType();
schema.setObjectTypes(Map.of("Foo", objectType));
GraphQLType type = GraphQLEnumType.newEnum().name("Foo").build();
assertThrows(IllegalStateException.class, () -> ModelHelper.getObjectType(schema, type));
}
use of org.dotwebstack.framework.core.model.Schema in project dotwebstack-framework by dotwebstack.
the class ModelHelperTest method getObjectType_throwException_forNonExistingObjectType.
@Test
void getObjectType_throwException_forNonExistingObjectType() {
Schema schema = new Schema();
ObjectType<?> objectType = new TestObjectType();
schema.setObjectTypes(Map.of("Bar", objectType));
GraphQLType type = GraphQLObjectType.newObject().name("Foo").build();
assertThrows(IllegalStateException.class, () -> ModelHelper.getObjectType(schema, type));
}
use of org.dotwebstack.framework.core.model.Schema in project dotwebstack-framework by dotwebstack.
the class ModelHelperTest method getObjectType_returnsObjectType_forGraphQlObjectType.
@Test
void getObjectType_returnsObjectType_forGraphQlObjectType() {
Schema schema = new Schema();
ObjectType<?> objectType = new TestObjectType();
schema.setObjectTypes(Map.of("Foo", objectType));
GraphQLType type = GraphQLObjectType.newObject().name("Foo").build();
ObjectType<?> result = ModelHelper.getObjectType(schema, type);
assertThat(result, is(objectType));
}
Aggregations