This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch CAUSEWAY-3676 in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 1671089b5ab2dbe8fad692f56d544d0e357beeef Author: danhaywood <[email protected]> AuthorDate: Mon Feb 12 23:47:43 2024 +0000 CAUSEWAY-3676: factors out GqlvMetaId --- .../viewer/graphql/model/domain/GqlvMeta.java | 14 +++--- .../viewer/graphql/model/domain/GqlvMetaId.java | 54 ++++++++++++++++++++++ .../Calculator_IntegTest.concat.approved.json | 2 +- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java index 2ea75e518c..02d284a6f7 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java @@ -44,10 +44,10 @@ import lombok.val; public class GqlvMeta extends GqlvAbstractCustom { - static GraphQLFieldDefinition id = newFieldDefinition().name("id").type(nonNull(Scalars.GraphQLString)).build(); static GraphQLFieldDefinition logicalTypeName = newFieldDefinition().name("logicalTypeName").type(nonNull(Scalars.GraphQLString)).build(); static GraphQLFieldDefinition version = newFieldDefinition().name("version").type(Scalars.GraphQLString).build(); + private final GqlvMetaId metaId; private final Holder holder; public GqlvMeta( @@ -58,8 +58,9 @@ public class GqlvMeta extends GqlvAbstractCustom { this.holder = holder; + metaId = new GqlvMetaId(context); + addChildField(metaId.getField()); - addChildField(id); addChildField(logicalTypeName); if (this.holder.getObjectSpecification().getBeanSort() == BeanSort.ENTITY) { addChildField(version); @@ -71,14 +72,15 @@ public class GqlvMeta extends GqlvAbstractCustom { @Override protected void addDataFetchersForChildren() { + metaId.addDataFetcher(this); +// context.codeRegistryBuilder.dataFetcher( +// coordinates(getGqlObjectType(), metaId.getField()), +// (DataFetcher<Object>) environment -> environment.<Fetcher>getSource().id()); + context.codeRegistryBuilder.dataFetcher( coordinates(getGqlObjectType(), logicalTypeName), (DataFetcher<Object>) environment -> environment.<Fetcher>getSource().logicalTypeName()); - context.codeRegistryBuilder.dataFetcher( - coordinates(getGqlObjectType(), id), - (DataFetcher<Object>) environment -> environment.<Fetcher>getSource().id()); - if (holder.getObjectSpecification().getBeanSort() == BeanSort.ENTITY) { context.codeRegistryBuilder.dataFetcher( coordinates(getGqlObjectType(), version), diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaId.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaId.java new file mode 100644 index 0000000000..72345e2b1d --- /dev/null +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaId.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.causeway.viewer.graphql.model.domain; + +import java.util.Objects; +import java.util.Optional; + +import graphql.Scalars; +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; +import graphql.schema.GraphQLFieldDefinition; + +import static graphql.schema.FieldCoordinates.coordinates; +import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; +import static graphql.schema.GraphQLNonNull.nonNull; + +import org.apache.causeway.applib.services.bookmark.Bookmark; +import org.apache.causeway.applib.services.bookmark.BookmarkService; +import org.apache.causeway.applib.services.metamodel.BeanSort; +import org.apache.causeway.core.metamodel.facets.object.entity.EntityFacet; +import org.apache.causeway.core.metamodel.objectmanager.ObjectManager; +import org.apache.causeway.viewer.graphql.model.context.Context; +import org.apache.causeway.viewer.graphql.model.mmproviders.ObjectSpecificationProvider; + +public class GqlvMetaId extends GqlvAbstract { + + public GqlvMetaId(final Context context) { + super(context); + + setField(newFieldDefinition().name("id").type(nonNull(Scalars.GraphQLString)).build()); + } + + @Override + protected String fetchData(DataFetchingEnvironment environment) { + return environment.<GqlvMeta.Fetcher>getSource().id(); + } + +} diff --git a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Calculator_IntegTest.concat.approved.json b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Calculator_IntegTest.concat.approved.json index 6f44d5df24..1228dcf7e8 100644 --- a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Calculator_IntegTest.concat.approved.json +++ b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Calculator_IntegTest.concat.approved.json @@ -2,7 +2,7 @@ "data" : { "Scenario" : { "Name" : "Fizz and buzz are concatenated together", - "Given" : { + "When" : { "university_calc_Calculator" : { "concat" : { "invoke" : "FizzBuzz"
