Skip to content

Instantly share code, notes, and snippets.

@ceefour
Last active September 20, 2017 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceefour/b721750ba2c2e1440e8c2059fc595db3 to your computer and use it in GitHub Desktop.
Save ceefour/b721750ba2c2e1440e8c2059fc595db3 to your computer and use it in GitHub Desktop.
GraphQL Java
type Query {
countries: [Country!]
}
# Country in the world
type Country {
# ISO 3-letter country code
code: ID!
# Formal name of country
name: String!
continent: String
region: String
surfaceArea: String
indepYear: String
population: String
lifeExpectancy: Float
gnp: Float
gnpOld: Float
localName: String
governmentForm: String
headOfState: String
# ISO 2-letter country code
code2: String
}
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>3.9.0</version>
</dependency>
package com.hendyirawan.jws1051;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class Query implements GraphQLQueryResolver {
@Autowired
private CountryRepository countryRepo;
public List<Country> countries() {
return countryRepo.findAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment