我正在将graphql模式添加到现有的Spring Boot服务中。我认为我的resources / graphql目录中的架构文件未加载。 springBootVersion ='1.4.5.RELEASE'
以下是gradle.build文件中的版本。 编译“ com.auth0:java-jwt:3.2.0” // https://mvnrepository.com/artifact/com.graphql-java/graphiql-spring-boot-starter 编译组:“ com.graphql-java”,名称:“ graphql-spring-boot-starter”,版本:“ 5.0.2”
// https://mvnrepository.com/artifact/com.graphql-java/graphiql-spring-boot-starter
compile group: 'com.graphql-java', name: 'graphiql-spring-boot-starter', version: '5.0.2'
// https://mvnrepository.com/artifact/com.graphql-java/graphiql-spring-boot-starter
compile group: 'com.graphql-java', name: 'graphql-java-tools', version: '5.2.4'
// https://mvnrepository.com/artifact/com.graphql-java/graphql-java-servlet
compile group: 'com.graphql-java', name: 'graphql-java-servlet', version: '4.7.0'
// https://mvnrepository.com/artifact/com.graphql-java-kickstart/graphiql-spring-boot-starter
compile group: 'com.graphql-java-kickstart', name: 'voyager-spring-boot-starter', version: '5.0.3'
架构文件- Provisioningaccount.graphqls(在resources / graphql目录下)
schema {
query: Query
mutation: Mutation
}
type ProvisioningAccount {
id:ID!
name: String
description: String
isLocked: Boolean
isDisabled: Boolean
associatedtype: String
failedLoginAttempts: Int
associatedType: String
credential: Credential
}
type Credential {
credentialNamespace: String
credentialAccount: String
credentialPassword: String
credentialType: CredentialType
}
enum CredentialType{
LOGIN
NTLM_LOGIN
DIGEST
SITE
}
input createAccountInput {
machineAccountName: String
password: String
associatedtype: String
disabled: Boolean
locked: Boolean
tenantId: String
description: String
}
type Query {
# get account by tenantId,
provisioningAccounts(tenantId: String): [ProvisioningAccount]
}
type Mutation {
createAccount(accountInput: createAccountInput): ProvisioningAccount
}
这是我的解析器:
import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import com.polycom.rpum.commonuser.services.IZtpProvAccountService;
import com.polycom.rpum.commonuser.shared.dataobject.MachineAccount;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
public class ProvAccountResolver implements GraphQLMutationResolver {
@Autowired
IZtpProvAccountService ztpProvAccountService;
public Optional<MachineAccount> createAccount(String tenantId, MachineAccount account) throws Exception {
MachineAccount machineAccount= this.ztpProvAccountService.createZtpProvAccount(tenantId,null, account,null);
return Optional.of(machineAccount);
}
}
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.polycom.rpum.commonuser.services.IZtpProvAccountService;
import com.polycom.rpum.commonuser.shared.dataobject.MachineAccount;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
public class ProvAccountQuery implements GraphQLQueryResolver {
@Autowired
IZtpProvAccountService ztpProvAccountService;
public List<MachineAccount> getProvisioningAccounts(String tenantId) throws Exception{
return ztpProvAccountService.getZtpProvAccounts(tenantId);
}
}
如果/ graphql servlet正确解析并正确加载了模式文件,似乎/ graphql servlet没有返回我期望的定义:
来自/ grapql发布请求的响应: {“ data”:{“ __ schema”:{“ queryType”:{“ name”:“ query”},“ mutationType”:null,“ subscriptionType”:null,“ types”:[{“ kind”:“ OBJECT” ,“名称”:“查询”,“描述”:null,“字段”:[{“名称”:“测试”,“描述”:null,“参数”:[],“类型”:{“种类” :“ SCALAR”,“名称”:“ String”,“ ofType”:null},“ isDeprecated”:false,“ deprecationReason”:null}],“ inputFields”:null,“ interfaces”:[],“ enumValues” :null,“ possibleTypes”:null},{“ kind”:“ SCALAR”,“ name”:“ String”,“ description”:“内置字符串”,“ fields”:null,“ inputFields”:null, “ interfaces”:null,“ enumValues”:null,“ possibleTypes”:null},{“ kind”:“ OBJECT”,“ name”:“ __ Schema”,“ description”:“ GraphQL自省定义了GraphQL的功能服务器。它公开了服务器上所有可用的类型和指令,以及查询,变异和订阅操作的入口点。“,”字段“:[{”名称“:”类型“,”描述“:”所有列表服务器支持的类型。“,” args“:[],” type“:{” kind“:” NON_NULL“,” name“:null,” ofType“:{” kind“:” LIST“,” name“ :null,“ ofType”:{“ kind”:“ NON_NULL”,“ name”:nu ll,“ ofType”:{“种类”:“对象”,“名称”:“ __ Type”,“ ofType”:null}}}},“ isDeprecated”:false,“ deprecationReason”:null},{“ name” :“ queryType”,“ description”:“查询操作将基于的类型。”,“ args”:[],“ type”:{“ kind”:“ NON_NULL