{"id":5528,"date":"2018-07-26T07:00:06","date_gmt":"2018-07-26T14:00:06","guid":{"rendered":"http:\/\/www.couchbase.com\/blog\/?p=5528"},"modified":"2023-09-11T00:09:32","modified_gmt":"2023-09-11T07:09:32","slug":"processing-graphql-queries-with-java-spring-boot-and-nosql","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/es\/processing-graphql-queries-with-java-spring-boot-and-nosql\/","title":{"rendered":"Procesamiento de consultas GraphQL con Java, Spring Boot y NoSQL"},"content":{"rendered":"<p>Over the span of the past few months I&#8217;ve been learning about GraphQL and how to use it as an alternative to RESTful API development. The focus thus far had been around <a href=\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\" target=\"_blank\" rel=\"noopener\">GraphQL and Golang<\/a> as well as <a href=\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\" target=\"_blank\" rel=\"noopener\">GraphQL and Node.js<\/a>. I might have squeeze out all I can on those two development languages so I&#8217;ve decided to switch gears and press my luck with some Java.<\/p>\n<p>In this tutorial, we&#8217;re going to see how to quickly get up and running with GraphQL using Java and the popular Spring Boot framework.<\/p>\n<p><!--more--><\/p>\n<p>Before we get into things, I want to give credit where credit is deserved.\u00a0Prithviraj Pawar wrote a great article titled,\u00a0<a href=\"https:\/\/medium.freecodecamp.org\/graphql-java-development-stack-in-production-21f402c4c37a\" target=\"_blank\" rel=\"noopener\">How to get Your GraphQL Java Server Up and Running in no Time<\/a>, which gave me a lot of ideas even though there were things to be desired, such as a database instead of mock data. I encourage you to read his article after reading through mine.<\/p>\n<h2>The Requirements<\/h2>\n<p>There are a few prerequisites that must be met before we jump into the GraphQL and development side of things.<\/p>\n<p>We&#8217;re going to assume that you already have Couchbase installed, configured, and running. Anything after Couchbase Server 5.0 will do because we&#8217;re only going to be using basic features.<\/p>\n<p>We&#8217;re also going to assume that you&#8217;ve downloaded a Spring Boot base project. The <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener\">Spring Boot website<\/a> has a great generator that lets you define the dependencies. If you want to stay consistent to my guide, you&#8217;ll need to create a Gradle project rather than Maven.<\/p>\n<h2>Defining the Gradle Project Dependencies<\/h2>\n<p>When you have a Spring Boot template in hand, it will likely be very bare. We need to include the dependencies we plan to use in our Gradle configuration.<\/p>\n<p>Open the project&#8217;s\u00a0<strong>build.gradle<\/strong> file and include the following:<\/p>\n<pre class=\"lang:default decode:true\">dependencies {\r\n    compile('org.springframework.boot:spring-boot-starter-web')\r\n    compile('com.couchbase.client:java-client')\r\n    compile('com.graphql-java:graphql-java:9.0')\r\n    testCompile('org.springframework.boot:spring-boot-starter-test')\r\n}<\/pre>\n<p>We&#8217;ll be using Spring Boot to serve our GraphQL endpoint, the Couchbase Java SDK for interactions with our database, and the GraphQL plugin for our query processing.<\/p>\n<h2>Bootstrapping the Java API with RESTful Endpoints<\/h2>\n<p>With the dependencies in place, we can start developing our API. Even though we&#8217;re using GraphQL as a replacement to all the common RESTful API stuff, it doesn&#8217;t mean that REST is completely out of the equation. We still need an endpoint to send our GraphQL queries to.<\/p>\n<p>Depending on what you named your project, package, etc., open the file that contains your <code>main<\/code> function and include the following:<\/p>\n<pre class=\"lang:default decode:true \">package com.couchbase.graphql;\r\n\r\nimport com.couchbase.client.java.Bucket;\r\nimport com.couchbase.client.java.Cluster;\r\nimport com.couchbase.client.java.CouchbaseCluster;\r\nimport com.couchbase.client.java.document.json.JsonObject;\r\nimport graphql.schema.DataFetcher;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.http.HttpStatus;\r\nimport org.springframework.http.ResponseEntity;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RestController;\r\nimport graphql.ExecutionInput;\r\nimport graphql.ExecutionResult;\r\nimport graphql.GraphQL;\r\nimport graphql.schema.GraphQLSchema;\r\nimport graphql.schema.StaticDataFetcher;\r\nimport graphql.schema.idl.RuntimeWiring;\r\nimport graphql.schema.idl.SchemaGenerator;\r\nimport graphql.schema.idl.SchemaParser;\r\nimport graphql.schema.idl.TypeDefinitionRegistry;\r\n\r\nimport javax.annotation.PostConstruct;\r\n\r\nimport static graphql.schema.idl.RuntimeWiring.newRuntimeWiring;\r\n\r\nimport java.io.File;\r\nimport java.nio.file.Files;\r\nimport java.nio.file.Paths;\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\n@SpringBootApplication\r\n@RestController\r\npublic class GraphqlApplication {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(GraphqlApplication.class, args);\r\n\t}\r\n\r\n\t@RequestMapping(value=\"\/\", method= RequestMethod.GET)\r\n\tpublic Object rootEndpoint() {\r\n        Map&lt;String, Object&gt; response = new HashMap&lt;String, Object&gt;();\r\n        response.put(\"message\", \"Hello World\");\r\n        return response;\r\n\t}\r\n\r\n    @RequestMapping(value=\"\/graphql\", method= RequestMethod.POST)\r\n    public Object graphql(@RequestBody String request) {\r\n        JsonObject jsonRequest = JsonObject.fromJson(request);\r\n        return jsonRequest;\r\n    }\r\n}<\/pre>\n<p>Remember, your package and class name may not match mine. Fill in the gaps where appropriate.<\/p>\n<p>You&#8217;ll notice that we have two endpoints, where one is completely optional. I created the <code>rootEndpoint<\/code> as a way to test that my RESTful API was in fact working. The <code>graphql<\/code> endpoint is where we&#8217;re going to be spending our time. It expects a POST request as well as a request body. The request body will eventually be an actual GraphQL query, but for now we can leave it as is.<\/p>\n<h2>Designing a GraphQL Schema Document<\/h2>\n<p>Up until now we&#8217;ve only done some basic Spring Boot preparation work and nothing really related to GraphQL. For GraphQL to be possible, we need to know a defined schema that explains the queries that are available as well as the types of data that we are working with. There are numerous ways to do this, but we&#8217;re going to focus on a schema document.<\/p>\n<p>Within the <strong>resources<\/strong> directory of your project, include a\u00a0<strong>schema.graphql<\/strong> file that contains the following:<\/p>\n<pre class=\"lang:default decode:true \">type Query{\r\n    pokemons: [Pokemon]\r\n    games: [Game]\r\n    game(id: String): Game\r\n}\r\ntype Game {\r\n    id: String\r\n    name: String\r\n}\r\ntype Pokemon {\r\n    id: String\r\n    game: Game\r\n    name: String\r\n    height: Int\r\n    weight: Int\r\n}<\/pre>\n<p>In case it isn&#8217;t obvious, we&#8217;re going to be working with Pokemon data. In the above file we&#8217;ve defined the queries that are available and the two data types that are available.<\/p>\n<p>There are a variety of Pokemon games on the market and there are different Pokemon in each of the games, hence the relationship that we&#8217;ve defined. If you&#8217;re a true Pokemon fan you&#8217;ll know there is a little bit more to it than this, but for this example it is enough.<\/p>\n<h2>Developing the Fetching Logic for the Couchbase NoSQL Database<\/h2>\n<p>With the schema defined, we need to come up with database logic to be ran when a query is executed and that database logic must return results that match each of the two data types.<\/p>\n<p>To make our lives a bit easier when it comes to project maintenance, we&#8217;re going to create a separate file for managing the database. Within your package, create a\u00a0<strong>Database.java<\/strong> file that contains the following:<\/p>\n<pre class=\"lang:default decode:true \">package com.couchbase.graphql;\r\n\r\nimport com.couchbase.client.java.Bucket;\r\nimport com.couchbase.client.java.document.JsonDocument;\r\nimport com.couchbase.client.java.document.json.JsonObject;\r\nimport com.couchbase.client.java.query.N1qlQuery;\r\nimport com.couchbase.client.java.query.N1qlQueryResult;\r\nimport com.couchbase.client.java.query.N1qlQueryRow;\r\nimport graphql.schema.DataFetcher;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.HashMap;\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\npublic class Database {\r\n\r\n    public static DataFetcher getPokemonData(Bucket bucket) { }\r\n\r\n    public static DataFetcher getGameData(Bucket bucket) { }\r\n\r\n    public static DataFetcher getGamesData(Bucket bucket) { }\r\n\r\n    private static List&lt;Map&lt;String, Object&gt;&gt; extractResultOrThrow(N1qlQueryResult result) { }\r\n\r\n}<\/pre>\n<p>For the most part, the above set of functions should look familiar because we&#8217;ve defined them somewhat to match what we had in our GraphQL schema file.<\/p>\n<p>A few things to note before we start filling each of the functions:<\/p>\n<ol>\n<li>The bucket will be defined in our main project file shortly after we define our logic.<\/li>\n<li>GraphQL expects a certain type of response, hence the <code>extractResultOrThrow<\/code> wrapper function that we&#8217;ve created.<\/li>\n<\/ol>\n<p>With that noted, let&#8217;s start by creating the wrapper function. The <code>extractResultOrThrow<\/code> function will be used only on N1QL queries and it looks like the following:<\/p>\n<pre class=\"lang:default decode:true \">private static List&lt;Map&lt;String, Object&gt;&gt; extractResultOrThrow(N1qlQueryResult result) {\r\n    List&lt;Map&lt;String, Object&gt;&gt; content = new ArrayList&lt;Map&lt;String, Object&gt;&gt;();\r\n    for (N1qlQueryRow row : result) {\r\n        content.add(row.value().toMap());\r\n    }\r\n    return content;\r\n}<\/pre>\n<p>Essentially we&#8217;re just looping through a N1QL result set and creating a <code>List<\/code> of <code>Map<\/code> from it.<\/p>\n<p>Assuming that we have game data in our database, we can query for that data in the <code>getGamesData<\/code> function:<\/p>\n<pre class=\"lang:default decode:true \">public static DataFetcher getGamesData(Bucket bucket) {\r\n    return environment -&gt; {\r\n        System.out.println(\"FETCHING GAMES DATA...\");\r\n        String statement = \"SELECT example.* \"\r\n                + \"FROM example \"\r\n                + \"WHERE type = 'game'\";\r\n        N1qlQueryResult queryResult = bucket.query(N1qlQuery.simple(statement));\r\n        return extractResultOrThrow(queryResult);\r\n    };\r\n}<\/pre>\n<p>Using N1QL we can query for documents that match the <code>type<\/code> of <code>game<\/code> and process the results with our wrapper function. If you really wanted to be strict, instead of using a wildcard asterisk, you could define the properties that match your schema.<\/p>\n<p>The next function, <code>getPokemonData<\/code>, will allow us to query for our Pokemon data in a similar fashion to how we did it with game data.<\/p>\n<pre class=\"lang:default decode:true \">public static DataFetcher getPokemonData(Bucket bucket) {\r\n    return environment -&gt; {\r\n        System.out.println(\"FETCHING POKEMON DATA...\");\r\n        String statement = \"SELECT example.* \"\r\n                         + \"FROM example \"\r\n                         + \"WHERE type = 'pokemon'\";\r\n        N1qlQueryResult queryResult = bucket.query(N1qlQuery.simple(statement));\r\n        return extractResultOrThrow(queryResult);\r\n    };\r\n}<\/pre>\n<p>You&#8217;ll notice that we didn&#8217;t do anything new beyond change the <code>type<\/code> property. This is where things can get interesting. We have a data relationship for Pokemon in regards to game data. We could either fetch it in our current query or break it up to be more modular and potentially more light weight. We&#8217;re going to go with the modular and light weight option.<\/p>\n<p>This brings us to our <code>getGameData<\/code> function:<\/p>\n<pre class=\"lang:default decode:true \">public static DataFetcher getGameData(Bucket bucket) {\r\n    return environment -&gt; {\r\n        HashMap&lt;String, Object&gt; parent = environment.getSource();\r\n        JsonDocument document;\r\n        if(parent != null) {\r\n            System.out.println(\"FETCHING GAME DATA FOR \" + (String)parent.get(\"game\") + \"...\");\r\n            document = bucket.get((String) parent.get(\"game\"));\r\n        } else {\r\n            System.out.println(\"FETCHING GAME DATA FOR \" + (String)environment.getArgument(\"id\") + \"...\");\r\n            document = bucket.get((String)environment.getArgument(\"id\"));\r\n        }\r\n        return document.content().toMap();\r\n    };\r\n}<\/pre>\n<p>There are two things happening in the above function, neither of which use N1QL.<\/p>\n<p>In our schema we have defined an argument based query for game data as well as a data relationship in the Pokemon data. We&#8217;re going to accommodate both those scenarios in the same function.<\/p>\n<p>Using the <code>environment.getSource()<\/code> function we can see if there is any parent data that goes with the request. An example of this parent data might be when we query for Pokemon data. The <code>game<\/code> field refers to the <code>getGameData<\/code> function while the other data such as the name, weight, or other, refers to the parent data. In the database, the game information is stored as an id so after we extract it from the parent data, we can do a lookup for game data.<\/p>\n<p>The other scenario is if we pass an argument that represents a game id.<\/p>\n<p>Both are valid and both do different things. In the end, we only want a single result rather than an array of results.<\/p>\n<h2>Wiring the Application Together for Successful GraphQL Processing<\/h2>\n<p>We are in the home stretch now. We&#8217;ve got our API and our database logic in place. The final step is to wire the GraphQL schema to the database logic and watch the results in all their glory.<\/p>\n<p>Remember in the previous step I mentioned configuring our bucket information? Let&#8217;s take care of that first. Open the project&#8217;s\u00a0<strong>application.properties<\/strong> file found in the\u00a0<strong>resources<\/strong> directory. Include the following:<\/p>\n<pre class=\"lang:default decode:true \">hostname=127.0.0.1\r\nbucket=example\r\nusername=example\r\npassword=123456<\/pre>\n<p>My database information is just an example. Make sure to replace it with the information that you&#8217;re using for your instance of Couchbase.<\/p>\n<p>Back in your main project file, we can map the values and connect to our instance:<\/p>\n<pre class=\"lang:default decode:true \">package com.couchbase.graphql;\r\n\r\nimport com.couchbase.client.java.Bucket;\r\nimport com.couchbase.client.java.Cluster;\r\nimport com.couchbase.client.java.CouchbaseCluster;\r\nimport com.couchbase.client.java.document.json.JsonObject;\r\nimport graphql.schema.DataFetcher;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.http.HttpStatus;\r\nimport org.springframework.http.ResponseEntity;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RestController;\r\nimport graphql.ExecutionInput;\r\nimport graphql.ExecutionResult;\r\nimport graphql.GraphQL;\r\nimport graphql.schema.GraphQLSchema;\r\nimport graphql.schema.StaticDataFetcher;\r\nimport graphql.schema.idl.RuntimeWiring;\r\nimport graphql.schema.idl.SchemaGenerator;\r\nimport graphql.schema.idl.SchemaParser;\r\nimport graphql.schema.idl.TypeDefinitionRegistry;\r\n\r\nimport javax.annotation.PostConstruct;\r\n\r\nimport static graphql.schema.idl.RuntimeWiring.newRuntimeWiring;\r\n\r\nimport java.io.File;\r\nimport java.nio.file.Files;\r\nimport java.nio.file.Paths;\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\n@SpringBootApplication\r\n@RestController\r\npublic class GraphqlApplication {\r\n\r\n    @Value(\"${hostname}\")\r\n    private String hostname;\r\n\r\n    @Value(\"${bucket}\")\r\n    private String bucket;\r\n\r\n    @Value(\"${username}\")\r\n    private String username;\r\n\r\n    @Value(\"${password}\")\r\n    private String password;\r\n\r\n    public @Bean\r\n    Cluster cluster() {\r\n        Cluster cluster = CouchbaseCluster.create(this.hostname);\r\n        cluster.authenticate(this.username, this.password);\r\n        return cluster;\r\n    }\r\n\r\n    public @Bean\r\n    Bucket bucket() {\r\n        return cluster().openBucket(this.bucket);\r\n    }\r\n\r\n    private GraphQL build;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(GraphqlApplication.class, args);\r\n\t}\r\n\r\n\t@RequestMapping(value=\"\/\", method= RequestMethod.GET)\r\n\tpublic Object rootEndpoint() { }\r\n\r\n    @RequestMapping(value=\"\/graphql\", method= RequestMethod.POST)\r\n    public Object graphql(@RequestBody String request) { }\r\n}<\/pre>\n<p>Notice that we&#8217;ve created two <code>Bean<\/code> and used the information from our properties file. Just like that we&#8217;re connected to Couchbase.<\/p>\n<p>The next step is to initialize our GraphQL schema. There are numerous ways to do this, but I found it easier using the Spring Boot annotation for when the application starts:<\/p>\n<pre class=\"lang:default decode:true \">@PostConstruct()\r\npublic void init() {\r\n    ClassLoader classLoader = getClass().getClassLoader();\r\n    File schemaFile = new File(classLoader.getResource(\"schema.graphql\").getFile());\r\n    SchemaParser schemaParser = new SchemaParser();\r\n    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schemaFile);\r\n    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()\r\n            .type(\"Query\",typeWiring -&gt; typeWiring\r\n                    .dataFetcher(\"pokemons\",Database.getPokemonData(bucket()))\r\n            )\r\n            .type(\"Query\",typeWiring -&gt; typeWiring\r\n                    .dataFetcher(\"games\",Database.getGamesData(bucket()))\r\n            )\r\n            .type(\"Query\",typeWiring -&gt; typeWiring\r\n                    .dataFetcher(\"game\",Database.getGameData(bucket()))\r\n            )\r\n            .type(\"Pokemon\",typeWiring -&gt; typeWiring\r\n                    .dataFetcher(\"game\",Database.getGameData(bucket()))\r\n            ).build();\r\n\r\n    SchemaGenerator schemaGenerator = new SchemaGenerator();\r\n    GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);\r\n    this.build = GraphQL.newGraphQL(graphQLSchema).build();\r\n}<\/pre>\n<p>The <code>init<\/code> function will be called when the application starts. It will load our schema file from the\u00a0<strong>resources<\/strong> directory and define wiring. For example, we know that <code>pokemons<\/code>, <code>games<\/code>, and <code>game(id: String)<\/code> are all types of queries. Each get mapped to the appropriate database function and the open bucket is passed. Then we establish a mapping of <code>game<\/code> to the <code>Pokemon<\/code> type. We are more or less defining how fields and queries are tied to database interaction.<\/p>\n<p>Once we build the schema we can tie it to our class variable. With the built schema, we can finalize our GraphQL RESTful endpoint:<\/p>\n<pre class=\"lang:default decode:true \">@RequestMapping(value=\"\/graphql\", method= RequestMethod.POST)\r\npublic Object graphql(@RequestBody String request) {\r\n    JsonObject jsonRequest = JsonObject.fromJson(request);\r\n    ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(jsonRequest.getString(\"query\")).build();\r\n    ExecutionResult executionResult = this.build.execute(executionInput);\r\n    return executionResult.toSpecification();\r\n}<\/pre>\n<p>In our endpoint we take the query string that was passed with the request and execute it with our built schema. The result will be whatever the client has asked for in the query.<\/p>\n<p>So what does a query look like? Take the following for example:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n  pokemons {\r\n    name\r\n    weight\r\n    game {\r\n      name\r\n    }\r\n  }\r\n  games {\r\n    name\r\n  }\r\n  game(id: \"game-2\") {\r\n    name\r\n  }\r\n}<\/pre>\n<p>The above query is probably not something anyone would ever need to run, but you could if you wanted to. In the above example we are querying for all Pokemon data and the game they are a part of. We are also querying for all games as well as a specific game. All three parts of the query are unrelated, but exist in the same query.<\/p>\n<p>As a cool fun fact, in the <code>pokemons<\/code> query, if we choose not to query for game data, the database function is never called. GraphQL will only execute functions as they are needed.<\/p>\n<h2>Conclusion<\/h2>\n<p>You just saw how to build a GraphQL application using Spring Boot, Java, and Couchbase Server as the NoSQL database. As you saw in my sample query, we were able to query many different unrelated pieces of data in a single request, something that would have required several in a RESTful API.<\/p>\n<p>For more information on using the Java SDK with Couchbase, check out the <a href=\"https:\/\/www.couchbase.com\/developers\/\" target=\"_blank\" rel=\"noopener\">Couchbase Developer Portal<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the span of the past few months I&#8217;ve been learning about GraphQL and how to use it as an alternative to RESTful API development. The focus thus far had been around GraphQL and Golang as well as GraphQL and [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":5529,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1816,1818,1812],"tags":[1393,2210],"ppma_author":[9032],"class_list":["post-5528","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-couchbase-server","category-java","category-n1ql-query","tag-api","tag-graphql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>GraphQL Queries: Convert + Build w\/ Java, Spring Boot, NoSQL<\/title>\n<meta name=\"description\" content=\"In this Couchbase tutorial, we\u2019re going to see how to quickly get up and running with GraphQL queries using Java, Spring Boot, and NoSQL frameworks.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/es\/processing-graphql-queries-with-java-spring-boot-and-nosql\/\" \/>\n<meta property=\"og:locale\" content=\"es_MX\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Processing GraphQL Queries with Java, Spring Boot, and NoSQL\" \/>\n<meta property=\"og:description\" content=\"In this Couchbase tutorial, we\u2019re going to see how to quickly get up and running with GraphQL queries using Java, Spring Boot, and NoSQL frameworks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/es\/processing-graphql-queries-with-java-spring-boot-and-nosql\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/thepolyglotdeveloper\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-26T14:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-11T07:09:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/07\/coffee-1580595_1920.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@nraboy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Processing GraphQL Queries with Java, Spring Boot, and NoSQL\",\"datePublished\":\"2018-07-26T14:00:06+00:00\",\"dateModified\":\"2023-09-11T07:09:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/\"},\"wordCount\":1690,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2018\\\/07\\\/coffee-1580595_1920.jpg\",\"keywords\":[\"API\",\"graphql\"],\"articleSection\":[\"Application Design\",\"Couchbase Server\",\"Java\",\"SQL++ \\\/ N1QL Query\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/\",\"name\":\"GraphQL Queries: Convert + Build w\\\/ Java, Spring Boot, NoSQL\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2018\\\/07\\\/coffee-1580595_1920.jpg\",\"datePublished\":\"2018-07-26T14:00:06+00:00\",\"dateModified\":\"2023-09-11T07:09:32+00:00\",\"description\":\"In this Couchbase tutorial, we\u2019re going to see how to quickly get up and running with GraphQL queries using Java, Spring Boot, and NoSQL frameworks.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2018\\\/07\\\/coffee-1580595_1920.jpg\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2018\\\/07\\\/coffee-1580595_1920.jpg\",\"width\":1920,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/processing-graphql-queries-with-java-spring-boot-and-nosql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Processing GraphQL Queries with Java, Spring Boot, and NoSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/admin-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/bb545ebe83bb2d12f91095811d0a72e1\",\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g8863514d8bed0cf6080f23db40e00354\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"caption\":\"Nic Raboy, Developer Advocate, Couchbase\"},\"description\":\"Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.\",\"sameAs\":[\"https:\\\/\\\/www.thepolyglotdeveloper.com\",\"https:\\\/\\\/www.facebook.com\\\/thepolyglotdeveloper\",\"https:\\\/\\\/x.com\\\/nraboy\"],\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/es\\\/author\\\/nic-raboy-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"GraphQL Queries: Convert + Build w\/ Java, Spring Boot, NoSQL","description":"En este tutorial de Couchbase, vamos a ver c\u00f3mo poner r\u00e1pidamente en marcha consultas GraphQL usando Java, Spring Boot y frameworks NoSQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/es\/processing-graphql-queries-with-java-spring-boot-and-nosql\/","og_locale":"es_MX","og_type":"article","og_title":"Processing GraphQL Queries with Java, Spring Boot, and NoSQL","og_description":"In this Couchbase tutorial, we\u2019re going to see how to quickly get up and running with GraphQL queries using Java, Spring Boot, and NoSQL frameworks.","og_url":"https:\/\/www.couchbase.com\/blog\/es\/processing-graphql-queries-with-java-spring-boot-and-nosql\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2018-07-26T14:00:06+00:00","article_modified_time":"2023-09-11T07:09:32+00:00","og_image":[{"width":1920,"height":1024,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/07\/coffee-1580595_1920.jpg","type":"image\/jpeg"}],"author":"Nic Raboy, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@nraboy","twitter_misc":{"Written by":"Nic Raboy, Developer Advocate, Couchbase","Est. reading time":"8 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Processing GraphQL Queries with Java, Spring Boot, and NoSQL","datePublished":"2018-07-26T14:00:06+00:00","dateModified":"2023-09-11T07:09:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/"},"wordCount":1690,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/07\/coffee-1580595_1920.jpg","keywords":["API","graphql"],"articleSection":["Application Design","Couchbase Server","Java","SQL++ \/ N1QL Query"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/","url":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/","name":"GraphQL Queries: Convert + Build w\/ Java, Spring Boot, NoSQL","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/07\/coffee-1580595_1920.jpg","datePublished":"2018-07-26T14:00:06+00:00","dateModified":"2023-09-11T07:09:32+00:00","description":"En este tutorial de Couchbase, vamos a ver c\u00f3mo poner r\u00e1pidamente en marcha consultas GraphQL usando Java, Spring Boot y frameworks NoSQL.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/07\/coffee-1580595_1920.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/07\/coffee-1580595_1920.jpg","width":1920,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Processing GraphQL Queries with Java, Spring Boot, and NoSQL"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"El blog de Couchbase","description":"Couchbase, la base de datos NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"El blog de Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1","name":"Nic Raboy, Defensor del Desarrollador, Couchbase","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g8863514d8bed0cf6080f23db40e00354","url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","caption":"Nic Raboy, Developer Advocate, Couchbase"},"description":"Nic Raboy es un defensor de las tecnolog\u00edas modernas de desarrollo web y m\u00f3vil. Tiene experiencia en Java, JavaScript, Golang y una variedad de frameworks como Angular, NativeScript y Apache Cordova. Nic escribe sobre sus experiencias de desarrollo relacionadas con hacer el desarrollo web y m\u00f3vil m\u00e1s f\u00e1cil de entender.","sameAs":["https:\/\/www.thepolyglotdeveloper.com","https:\/\/www.facebook.com\/thepolyglotdeveloper","https:\/\/x.com\/nraboy"],"url":"https:\/\/www.couchbase.com\/blog\/es\/author\/nic-raboy-2\/"}]}},"acf":[],"authors":[{"term_id":9032,"user_id":63,"is_guest":0,"slug":"nic-raboy-2","display_name":"Nic Raboy, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/5528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/comments?post=5528"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/5528\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media\/5529"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media?parent=5528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/categories?post=5528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/tags?post=5528"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/ppma_author?post=5528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}