Search in sources :

Example 1 with DateSupplier

use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.

the class MapHelperTest method getNestedMap_returnsValue_forNestedSupplier.

@Test
void getNestedMap_returnsValue_forNestedSupplier() {
    LocalDate date = LocalDate.of(2020, 1, 1);
    Map<String, Object> data = new HashMap<>();
    data.put("key", new DateSupplier(false, date));
    Map<String, Object> arguments = Map.of("arg", Map.of("arg1", data));
    Map<String, Object> result = getNestedMap(arguments, "arg");
    assertThat(result, is(Map.of("arg1", Map.of("key", date))));
}
Also used : HashMap(java.util.HashMap) LocalDate(java.time.LocalDate) DateSupplier(org.dotwebstack.framework.core.scalars.DateSupplier) Test(org.junit.jupiter.api.Test)

Example 2 with DateSupplier

use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.

the class BackendRequestFactoryTest method initExecutionStepInfoMock.

private ExecutionStepInfo initExecutionStepInfoMock() {
    var executionStepInfo = mock(ExecutionStepInfo.class);
    var resultPath = ResultPath.rootPath().segment("a");
    lenient().when(executionStepInfo.getPath()).thenReturn(resultPath);
    var objectType = mock(GraphQLObjectType.class);
    lenient().when(objectType.getName()).thenReturn("Brewery");
    lenient().when(executionStepInfo.getType()).thenReturn(objectType);
    var date = LocalDate.of(2021, 1, 1);
    Map<String, Object> data = new HashMap<>();
    Map<String, Object> argument = Map.of("name", Map.of("eq", "name-value"));
    data.put("key", new DateSupplier(false, date));
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("arg", Map.of("arg1", data));
    arguments.put("filter", argument);
    lenient().when(executionStepInfo.getArguments()).thenReturn(arguments);
    lenient().when(executionStepInfo.getArgument(eq("filter"))).thenReturn(argument);
    lenient().when(executionStepInfo.getArgument(eq("sort"))).thenReturn("NAME");
    var fieldDefinitionBuilder = newFieldDefinition();
    List<GraphQLArgument> argumentList = new ArrayList<>();
    fieldDefinitionBuilder.arguments(argumentList);
    fieldDefinitionBuilder.name("a");
    fieldDefinitionBuilder.description("any");
    fieldDefinitionBuilder.type(mock(GraphQLOutputType.class));
    fieldDefinitionBuilder.definition(FieldDefinition.newFieldDefinition().build());
    when(executionStepInfo.getFieldDefinition()).thenReturn(fieldDefinitionBuilder.build());
    return executionStepInfo;
}
Also used : GraphQLOutputType(graphql.schema.GraphQLOutputType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GraphQLArgument(graphql.schema.GraphQLArgument) DateSupplier(org.dotwebstack.framework.core.scalars.DateSupplier)

Example 3 with DateSupplier

use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.

the class BackendRequestFactoryTest method createRequestContext_returnsRequestContext_whithObjectFieldType_Address.

@Test
void createRequestContext_returnsRequestContext_whithObjectFieldType_Address() {
    LocalDate date = LocalDate.of(2021, 1, 1);
    Map<String, Object> data = new HashMap<>();
    data.put("key", new DateSupplier(false, date));
    Map<String, Object> source = Map.of("arg", Map.of("arg1", data));
    DataFetchingEnvironmentImpl.Builder envBuilder = new DataFetchingEnvironmentImpl.Builder();
    envBuilder.source(source);
    ExecutionStepInfo executionStepInfo = mock(ExecutionStepInfo.class);
    GraphQLObjectType objectType = mock(GraphQLObjectType.class);
    when(objectType.getName()).thenReturn("Brewery");
    when(executionStepInfo.getObjectType()).thenReturn(objectType);
    MergedField mergedField = mock(MergedField.class);
    when(mergedField.getName()).thenReturn("addresses");
    when(executionStepInfo.getField()).thenReturn(mergedField);
    envBuilder.executionStepInfo(executionStepInfo);
    envBuilder.fieldDefinition(newFieldDefinition().name("field").type(Scalars.GraphQLID).definition(FieldDefinition.newFieldDefinition().additionalData(GraphQlConstants.IS_PAGING_NODE, Boolean.TRUE.toString()).build()).build());
    envBuilder.fieldDefinition(newFieldDefinition().name("field").type(Scalars.GraphQLID).definition(FieldDefinition.newFieldDefinition().additionalData(GraphQlConstants.IS_PAGING_NODE, Boolean.TRUE.toString()).build()).build());
    var schema = testHelper.loadSchema("dotwebstack/dotwebstack-objecttypes.yaml");
    var backendRequestFactory = new BackendRequestFactory(schema, new BackendExecutionStepInfo());
    var result = backendRequestFactory.createRequestContext(envBuilder.build());
    assertThat(result, is(notNullValue()));
    assertThat(result.getObjectField().getName(), is("addresses"));
    assertThat(result.getObjectField().getType(), is("Address"));
}
Also used : HashMap(java.util.HashMap) DataFetchingEnvironmentImpl(graphql.schema.DataFetchingEnvironmentImpl) LocalDate(java.time.LocalDate) DateSupplier(org.dotwebstack.framework.core.scalars.DateSupplier) ExecutionStepInfo(graphql.execution.ExecutionStepInfo) MergedField(graphql.execution.MergedField) GraphQLObjectType(graphql.schema.GraphQLObjectType) Test(org.junit.jupiter.api.Test)

Example 4 with DateSupplier

use of org.dotwebstack.framework.core.scalars.DateSupplier in project dotwebstack-framework by dotwebstack.

the class MapHelperTest method getNestedMap_returnsValue_forSupplier.

@Test
void getNestedMap_returnsValue_forSupplier() {
    LocalDate date = LocalDate.of(2020, 1, 1);
    Map<String, Object> data = new HashMap<>();
    data.put("key", new DateSupplier(false, date));
    Map<String, Object> arguments = Map.of("arg", data);
    Map<String, Object> result = getNestedMap(arguments, "arg");
    assertThat(result, is(Map.of("key", date)));
}
Also used : HashMap(java.util.HashMap) LocalDate(java.time.LocalDate) DateSupplier(org.dotwebstack.framework.core.scalars.DateSupplier) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)4 DateSupplier (org.dotwebstack.framework.core.scalars.DateSupplier)4 LocalDate (java.time.LocalDate)3 Test (org.junit.jupiter.api.Test)3 ExecutionStepInfo (graphql.execution.ExecutionStepInfo)1 MergedField (graphql.execution.MergedField)1 DataFetchingEnvironmentImpl (graphql.schema.DataFetchingEnvironmentImpl)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 ArrayList (java.util.ArrayList)1