脚本宝典收集整理的这篇文章主要介绍了graphql-java使用手册: part1 入门,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
入门
graphql-java
需要运行于 Java 8 或更高版本.
如何在 Gradle 中使用最新正式版本
首先,保证 mavenCentral
在你的 repos 库列表中:
repositories { mavenCentral() }
依赖:
dependencies { compile 'com.graphql-java:graphql-java:6.0' }
如果在 Maven 中使用最新正式版本
依赖:
<dependency> <groupId>com.graphql-java</groupId> <artifactId>graphql-java</artifactId> <version>6.0</version> </dependency>
Hello World【译注:这个用不翻译了吧 :) 】
下面就用 graphql-java
来实现经典的 “hello world” :
import graphql.ExecutionResult; import graphql.GraphQL; import graphql.schema.GraphQLSchema; import graphql.schema.StaticDataFetcher; import graphql.schema.idl.RuntimeWiring; import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring; public class HelloWorld { public static void main(String[] args) { String schema = "type Query{hello: String}"; SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema); RuntimeWiring runtimeWiring = newRuntimeWiring() .type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))) .build(); SchemaGenerator schemaGenerator = new SchemaGenerator(); GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring); GraphQL build = GraphQL.newGraphQL(graphQLSchema).build(); ExecutionResult executionResult = build.execute("{hello}"); System.out.println(executionResult.getData().toString()); // Prints: {hello=world} } }
如何使用最新的开发中版本
最近的开发中版本,可以在 Bintray 上获取.
可以从 最新版本 中看到最新的版本号.
如果在 Gradle 中使用最新的开发中版本
增加 repositories:
repositories { mavenCentral() maven { url "http://dl.bintray.com/andimarek/graphql-java" } }
依赖:
dependencies { compile 'com.graphql-java:graphql-java:INSERT_LATEST_VERSION_HERE' }
如果在 Maven 中使用最新的开发中版本
增加 repository:
<repository> <snapshots> <enabled>false</enabled> </snapshots> <id>bintray-andimarek-graphql-java</id> <name>bintray</name> <url>http://dl.bintray.com/andimarek/graphql-java</url> </repository>
依赖:
<dependency> <groupId>com.graphql-java</groupId> <artifactId>graphql-java</artifactId> <version>INSERT_LATEST_VERSION_HERE</version> </dependency>
以上是脚本宝典为你收集整理的graphql-java使用手册: part1 入门全部内容,希望文章能够帮你解决graphql-java使用手册: part1 入门所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。