Search in sources :

Example 1 with Schema

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;
}
Also used : Schema(org.dotwebstack.framework.core.model.Schema) OnLocalSchema(org.dotwebstack.framework.core.OnLocalSchema) Bean(org.springframework.context.annotation.Bean)

Example 2 with 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"));
}
Also used : TestObjectType(org.dotwebstack.framework.core.testhelpers.TestObjectType) Schema(org.dotwebstack.framework.core.model.Schema) ObjectField(org.dotwebstack.framework.core.model.ObjectField) TestObjectField(org.dotwebstack.framework.core.testhelpers.TestObjectField) Test(org.junit.jupiter.api.Test)

Example 3 with Schema

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));
}
Also used : TestObjectType(org.dotwebstack.framework.core.testhelpers.TestObjectType) Schema(org.dotwebstack.framework.core.model.Schema) GraphQLType(graphql.schema.GraphQLType) Test(org.junit.jupiter.api.Test)

Example 4 with Schema

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));
}
Also used : TestObjectType(org.dotwebstack.framework.core.testhelpers.TestObjectType) Schema(org.dotwebstack.framework.core.model.Schema) GraphQLType(graphql.schema.GraphQLType) Test(org.junit.jupiter.api.Test)

Example 5 with Schema

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));
}
Also used : TestObjectType(org.dotwebstack.framework.core.testhelpers.TestObjectType) Schema(org.dotwebstack.framework.core.model.Schema) GraphQLType(graphql.schema.GraphQLType) Test(org.junit.jupiter.api.Test)

Aggregations

Schema (org.dotwebstack.framework.core.model.Schema)9 TestObjectType (org.dotwebstack.framework.core.testhelpers.TestObjectType)5 Test (org.junit.jupiter.api.Test)5 GraphQLType (graphql.schema.GraphQLType)3 ObjectField (org.dotwebstack.framework.core.model.ObjectField)3 OnLocalSchema (org.dotwebstack.framework.core.OnLocalSchema)2 ObjectType (org.dotwebstack.framework.core.model.ObjectType)2 TestObjectField (org.dotwebstack.framework.core.testhelpers.TestObjectField)2 Scalars (graphql.Scalars)1 File (java.io.File)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 PostgresObjectType (org.dotwebstack.framework.backend.postgres.model.PostgresObjectType)1 FilterConfiguration (org.dotwebstack.framework.core.config.FilterConfiguration)1 FilterType (org.dotwebstack.framework.core.config.FilterType)1 SchemaReader (org.dotwebstack.framework.core.config.SchemaReader)1 ExceptionHelper.invalidConfigurationException (org.dotwebstack.framework.core.helpers.ExceptionHelper.invalidConfigurationException)1 TestBackendLoaderFactory (org.dotwebstack.framework.core.testhelpers.TestBackendLoaderFactory)1