0

我正在尝试将 Apollo-Android 与本地安装的服务器集成,显示所有条目的查询工作正常,但是当我尝试创建一个新条目时,它会发送一个不带参数的查询。

起初我认为这是一个服务器端问题,但看起来不像,因为它正在创建条目但具有空值。

它是在 Spring Boot 上使用 SPQR 生成模式的服务器,以及带有 Hibernate 的 SpringData-JPA 用于连接到 PostGreSQL 数据库。

这是服务器所说的:

Hibernate: insert into author (first_name, last_name) values (?, ?) 2018-06-25 14:48:25.479 INFO 6670 --- [nio-8080-exec-3] s.testing.controllers.GraphQLController : {data={createAuthor={__typename=Author, firstName=null, lastName=null}}}

这是我在 Android Studio 上得到的回应:

06-25 14:48:24.974 16068-16132/com.example.nburk.apollodemo D/graphcool: Executed mutation: CreateAuthor{__typename=Author, firstName=null, lastName=null}

在 Android Studio 中,这是构建器:

private void createPost(String firstname, String lastname) { application.apolloClient().mutate( CreateAuthorMutation.builder() .firstName(firstname) .lastName(lastname) .build()) .enqueue(createPostMutationCallback); }

排队:

private ApolloCall.Callback<CreateAuthorMutation.Data> createPostMutationCallback = new ApolloCall.Callback<CreateAuthorMutation.Data>() { @Override public void onResponse(@Nonnull final Response<CreateAuthorMutation.Data> dataResponse) { Log.d(ApolloDemoApplication.TAG, "Executed mutation: " + dataResponse.data().createAuthor().toString()); fetchPosts(); } @Override public void onFailure(@Nonnull ApolloException e) { Log.d(ApolloDemoApplication.TAG, "Error:" + e.toString()); } };

如果你需要它,这是我的突变:

mutation CreateAuthor($firstName: String, $lastName: String){ createAuthor(firstName: $firstName, lastName: $lastName){ firstName lastName } }

本项目基于此:https ://github.com/graphcool-examples/android-graphql/tree/master/quickstart-with-apollo

也上传我的架构。

Copia de schema.txt

预先感谢您的帮助。

4

1 回答 1

0

问题来自 SPQR,您需要为变量添加映射器

@PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public Map<String, Object> indexFromAnnotated(@RequestBody Map<String, Object> request, HttpServletRequest raw) { ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput() .query((String) request.get("query")) .operationName((String) request.get("operationName")) // -------- THIS RESOLVES THE VARIABLES-------- .variables((Map<String, Object>) request.get("variables")) .context(raw) .build()); LOGGER.info(executionResult.toSpecification().toString()); return executionResult.toSpecification(); }

于 2018-06-28T19:31:37.773 回答