{"id":5036,"date":"2018-04-23T09:46:20","date_gmt":"2018-04-23T16:46:20","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=5036"},"modified":"2025-06-13T20:15:00","modified_gmt":"2025-06-14T03:15:00","slug":"creating-a-graphql-application-with-node-js-and-a-nosql-database","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/","title":{"rendered":"Create a GraphQL Application With Node.js, NoSQL Databases"},"content":{"rendered":"<p>I&#8217;ve been hearing a lot of buzz around working with <a href=\"https:\/\/graphql.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">GraphQL<\/a> and NoSQL, internally within Couchbase and externally. Since it sounds like a hot topic, I figured I&#8217;d spend some time learning about it to see how it could be valuable when creating web applications.<\/p>\n<p>Coming from the world of RESTful APIs, GraphQL is a totally different concept to me even though it aims to solve a similar problem of accessing and mutating data via client facing applications. <span style=\"font-weight: 400\">Fortunately, Node.js and databases work hand-in-glove, so in the GraphQL-database example below we\u2019ll be <a href=\"https:\/\/www.couchbase.com\/blog\/build-a-rest-api-with-node-js-express-and-couchbase\/\">using Node.js<\/a> with<\/span> <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a> as our <a href=\"https:\/\/www.couchbase.com\/resources\/why-nosql\/\">NoSQL database<\/a> layer.<\/p>\n<p><!--more--><\/p>\n<p>As it stands right now, I&#8217;m not a GraphQL expert. I&#8217;ve been developing RESTful APIs with frameworks like Express and Hapi for many years. That said, I&#8217;m going to try to explain how I&#8217;ve learned about them.<\/p>\n<p>APIs work great, but when it comes to getting the information you need out of them, things can be done better. For example, what if you need a bunch of unrelated or loosely related data for your client? Do you create one massive endpoint that returns a lot of data or do you make a request to every API endpoint that might contain your data? What if you need only a fragment of the data returned from any particular endpoint?<\/p>\n<p>This is where GraphQL comes into play. Through the query language you can specify exactly what data you want returned to the client at any given time without writing an endpoint for everything.<\/p>\n<h2>Creating a New Node.js Application with Express Framework<\/h2>\n<p>We&#8217;re going to be using Node.js to create an interface for using <a href=\"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/\">GraphQL queries<\/a>. Let&#8217;s start by creating a new project, getting the dependencies and bootstrapping our project in preparation for some real logic.<\/p>\n<p>With Node.js installed, from the command line, execute:<\/p>\n<pre class=\"lang:default decode:true \">npm init -y\r\nnpm install couchbase --save\r\nnpm install express --save\r\nnpm install express-graphql --save\r\nnpm install graphql --save\r\nnpm install uuid --save<\/pre>\n<p>The above commands will initialize a new project by creating a\u00a0<strong>package.json<\/strong> file and installing the necessary dependencies. Of the dependencies, we&#8217;re installing Couchbase and a package for generating UUID strings that will later represent our document keys. The other packages are related to GraphQL and linking it to Express Framework.<\/p>\n<p>Create a file called\u00a0<strong>app.js<\/strong> within your project and include the following code:<\/p>\n<pre class=\"lang:default decode:true \">const Express = require(\"express\");\r\nconst Couchbase = require(\"couchbase\");\r\nconst ExpressGraphQL = require(\"express-graphql\");\r\nconst BuildSchema = require(\"graphql\").buildSchema;\r\nconst UUID = require(\"uuid\");\r\n\r\nvar schema = BuildSchema(``);\r\n\r\nvar resolvers = { };\r\n\r\nvar app = Express();\r\n\r\napp.use(\"\/graphql\", ExpressGraphQL({\r\n    schema: schema,\r\n    rootValue: resolvers,\r\n    graphiql: true\r\n}));\r\n\r\napp.listen(3000, () =&gt; {\r\n    console.log(\"Listening at :3000\");\r\n});<\/pre>\n<p>We&#8217;re not going to worry about populating our schema and configuring our database quite yet. In the above code, notice that we&#8217;ve imported each of our dependencies and initialized Express. We&#8217;ve also defined a single API endpoint which is how we&#8217;re going to get Couchbase and GraphQL to interact. Essentially, we&#8217;re going to issue every GraphQL query to that single endpoint and it will respond with the correct data based on our schema and resolvers.<\/p>\n<h2>Defining a GraphQL Schema and Resolvers<\/h2>\n<p>Now that we have the application foundation in place, let&#8217;s figure out a schema and the resolvers for actually linking the data to potential queries and data types.<\/p>\n<p>For this example, we&#8217;re going to create a simple blogging application. For this reason, it might make sense to have the following schema models:<\/p>\n<pre class=\"lang:default decode:true \">var schema = BuildSchema(`\r\n    type Account {\r\n        id: String,\r\n        firstname: String,\r\n        lastname: String,\r\n    }\r\n    type Blog {\r\n        id: String,\r\n        account: String!,\r\n        title: String,\r\n        content: String\r\n    }\r\n`);<\/pre>\n<p>We know we&#8217;ll have accounts and we know that we&#8217;ll have blog articles for any given account. The exclamation mark for any data type means that it is a required property.<\/p>\n<p>Now we need to hook our model up to Couchbase so we can query for data or even create data.<\/p>\n<h2>Querying and Mutating Data from Couchbase Server, the NoSQL Database<\/h2>\n<p>We&#8217;re going to assume that you already have <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a> running. There is no special configuration requirement of Couchbase for this particular example.<\/p>\n<p>The first step is to connect to Couchbase Server from the Node.js application. Within the project&#8217;s\u00a0<strong>app.js<\/strong> file, add the following lines:<\/p>\n<pre class=\"lang:default decode:true \">var cluster = new Couchbase.Cluster(\"couchbase:\/\/localhost\");\r\ncluster.authenticate(\"example\", \"123456\");\r\nvar bucket = cluster.openBucket(\"example\");<\/pre>\n<p>The above lines assume Node.js and the database &#8212; Couchbase, in this example &#8212; are running on the local machine. We&#8217;re going to be using a Bucket called <code>example<\/code> and an RBAC user account called <code>example<\/code>.<\/p>\n<p>The data models for GraphQL are already in place, but we haven&#8217;t defined the possible queries or mutations. Let&#8217;s modify the schema in our application to look like the following:<\/p>\n<pre class=\"lang:default decode:true \">var schema = BuildSchema(`\r\n    type Query {\r\n        account(id: String!): Account,\r\n        accounts: [Account],\r\n        blog(id: String!): Blog,\r\n        blogs(account: String!): [Blog]\r\n    }\r\n    type Account {\r\n        id: String,\r\n        firstname: String,\r\n        lastname: String,\r\n    }\r\n    type Blog {\r\n        id: String,\r\n        account: String!,\r\n        title: String,\r\n        content: String\r\n    }\r\n    type Mutation {\r\n        createAccount(firstname: String!, lastname: String!): Account\r\n        createBlog(account: String!, title: String!, content: String!): Blog\r\n    }\r\n`);<\/pre>\n<p>For both the queries and mutations, special resolver functions will be called which do the heavy lifting. As a result, either an <code>Account<\/code> or a <code>Blog<\/code> will be returned.<\/p>\n<p>Starting with the mutations, we are expecting a <code>createAccount<\/code> function that expects two parameters. It might look like the following:<\/p>\n<pre class=\"lang:default decode:true \">var resolvers = {\r\n    createAccount: (data) =&gt; {\r\n        var id = UUID.v4();\r\n        data.type = \"account\";\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.insert(id, data, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve({ \"id\": id });\r\n            });\r\n        });\r\n    }\r\n};<\/pre>\n<p>Notice that our resolver function only has one parameter even though we were passing two in our schema. All of our parameters for data will reside in the <code>data<\/code> variable. The function itself expects that we return a promise.<\/p>\n<p>You&#8217;ll notice that we are returning an <code>id<\/code> and nothing else. Remember, we expect an <code>Account<\/code> to be returned, but not every part of <code>Account<\/code> needs to be present. However, it might be better practice to return everything.<\/p>\n<pre class=\"lang:default decode:true \">var resolvers = {\r\n    createBlog: (data) =&gt; {\r\n        var id = UUID.v4();\r\n        data.type = \"blog\";\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.insert(id, data, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve({ \"id\": id });\r\n            });\r\n        });\r\n    }\r\n};<\/pre>\n<p>The <code>createBlog<\/code> function is pretty much the same as the previous function, with the exception that the input data is different and the <code>type<\/code> property is set to something else. All our functions will be in the same <code>resolvers<\/code> object.<\/p>\n<p>With the mutations out of the way, the data can be queried. Take the <code>account<\/code> function for example:<\/p>\n<pre class=\"lang:default decode:true \">var resolvers = {\r\n    account: (data) =&gt; {\r\n        var id = data.id;\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.get(id, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve(result.value);\r\n            });\r\n        });\r\n    }\r\n};<\/pre>\n<p>Nothing really different is happening between this particular query function versus the mutation function. We&#8217;re expecting an <code>id<\/code> to be passed and we&#8217;re using it to do a lookup.<\/p>\n<p>For retrieving all accounts, we can use a N1QL query:<\/p>\n<pre class=\"lang:default decode:true \">var resolvers = {\r\n    accounts: () =&gt; {\r\n        var statement = \"SELECT META(account).id, account.* FROM `\" + bucket._name + \"` AS account WHERE account.type = 'account'\";\r\n        var query = Couchbase.N1qlQuery.fromString(statement);\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.query(query, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve(result);\r\n            });\r\n        });\r\n    }\r\n};<\/pre>\n<p>Can you see the trend now when it comes to querying and mutating data? Just to finish the job, let&#8217;s look at our two final functions, one for getting a single blog and one for getting all blogs.<\/p>\n<pre class=\"lang:default decode:true \">var resolvers = {\r\n    blog: (data) =&gt; {\r\n        var id = data.id;\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.get(id, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve(result.value);\r\n            });\r\n        });\r\n    },\r\n    blogs: (data) =&gt; {\r\n        var statement = \"SELECT META(blog).id, blog.* FROM `\" + bucket._name + \"` AS blog WHERE blog.type = 'blog' AND blog.account = $account\";\r\n        var query = Couchbase.N1qlQuery.fromString(statement);\r\n        return new Promise((resolve, reject) =&gt; {\r\n            bucket.query(query, { \"account\": data.account }, (error, result) =&gt; {\r\n                if(error) {\r\n                    return reject(error);\r\n                }\r\n                resolve(result);\r\n            });\r\n        });\r\n    }\r\n};<\/pre>\n<p>At this point in time our application is complete. At least complete enough for this particular example. Now we should probably test it with some GraphQL queries.<\/p>\n<h2>Executing GraphQL Queries with the Graphical Interface<\/h2>\n<p>If you&#8217;re using Node.js and the GraphQL package for Express, you&#8217;ll get a nice graphical interface for executing queries. Navigate to\u00a0https:\/\/localhost:3000\/graphql in your web browser and you should see something that looks like the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5038 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/04\/graphql-nodejs.png\" alt=\"\" width=\"1500\" height=\"679\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs.png 1500w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs-300x136.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs-1024x464.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs-768x348.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs-20x9.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs-1320x598.png 1320w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/p>\n<p>So let&#8217;s create a mutation query that will insert data for us.<\/p>\n<pre class=\"lang:default decode:true \">mutation CreateAccount($firstname: String!, $lastname: String!) {\r\n  createAccount(firstname: $firstname, lastname: $lastname) {\r\n    id\r\n  }\r\n}<\/pre>\n<p>The above mutation will take in two mandatory parameters and then execute our <code>createAccount<\/code> function passing each of those parameters. The parameters can be set in the <strong>Query Variables<\/strong> section of the GraphQL explorer. The parameters would look something like this:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n  \"firstname\": \"Erika\",\r\n  \"lastname\": \"Raboy\"\r\n}<\/pre>\n<p>Upon a successful mutation, we&#8217;ll get the <code>id<\/code> which is what we requested. After we&#8217;ve filled our database with data, we could do a more sophisticated GraphQL query like the following:<\/p>\n<pre class=\"lang:default decode:true \">query GetAccountData($id: String!) {\r\n  account(id: $id) {\r\n    firstname\r\n    lastname\r\n  }\r\n  blogs(account: $id) {\r\n    title\r\n    content\r\n  }\r\n}<\/pre>\n<p>For the above query you&#8217;d pass in a valid account and it would return the account information as well as the blog information that that account had written. Through the GraphQL queries you can request certain properties or all properties while saving you from making multiple requests.<\/p>\n<h2>Conclusion<\/h2>\n<p>You just saw how to make a simple Node.js database leveraging GraphQL in <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a>. Just because GraphQL gives you a means to query for the data that you need, it doesn&#8217;t eliminate the need to write quality queries that communicate with your database. Remember, GraphQL is just a client facing query language, not a backend database query language. In other words, let Couchbase do the heavy lifting where it makes sense.<\/p>\n<p>If you&#8217;d like more help with the Node.js SDK for Couchbase, check out the <a href=\"https:\/\/www.couchbase.com\/developers\/\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Developer Portal<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been hearing a lot of buzz around working with GraphQL and NoSQL, internally within Couchbase and externally. Since it sounds like a hot topic, I figured I&#8217;d spend some time learning about it to see how it could be [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1816,9327,1822,1812],"tags":[1393,2210,1543,1725],"ppma_author":[9032],"class_list":["post-5036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-couchbase-server","category-javascript","category-node-js","category-n1ql-query","tag-api","tag-graphql","tag-javascript","tag-nosql-database"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.2 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Creating a GraphQL Application With Node.js and a NoSQL Database<\/title>\n<meta name=\"description\" content=\"Learn GraphQL for querying in a NoSQL Node.js database application that&#039;s built for Couchbase. You&#039;ll also learn when to use GraphQL, and when not to.\" \/>\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\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create a GraphQL Application With Node.js, NoSQL Databases\" \/>\n<meta property=\"og:description\" content=\"Learn GraphQL for querying in a NoSQL Node.js database application that&#039;s built for Couchbase. You&#039;ll also learn when to use GraphQL, and when not to.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\" \/>\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-04-23T16:46:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:15:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"679\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Create a GraphQL Application With Node.js, NoSQL Databases\",\"datePublished\":\"2018-04-23T16:46:20+00:00\",\"dateModified\":\"2025-06-14T03:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\"},\"wordCount\":1265,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"API\",\"graphql\",\"javascript\",\"NoSQL Database\"],\"articleSection\":[\"Application Design\",\"Couchbase Server\",\"JavaScript\",\"Node.js\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\",\"name\":\"Creating a GraphQL Application With Node.js and a NoSQL Database\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2018-04-23T16:46:20+00:00\",\"dateModified\":\"2025-06-14T03:15:00+00:00\",\"description\":\"Learn GraphQL for querying in a NoSQL Node.js database application that's built for Couchbase. You'll also learn when to use GraphQL, and when not to.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create a GraphQL Application With Node.js, NoSQL Databases\"}]},{\"@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\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@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\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354\",\"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\/author\/nic-raboy-2\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Creating a GraphQL Application With Node.js and a NoSQL Database","description":"Learn GraphQL for querying in a NoSQL Node.js database application that's built for Couchbase. You'll also learn when to use GraphQL, and when not to.","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\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/","og_locale":"en_US","og_type":"article","og_title":"Create a GraphQL Application With Node.js, NoSQL Databases","og_description":"Learn GraphQL for querying in a NoSQL Node.js database application that's built for Couchbase. You'll also learn when to use GraphQL, and when not to.","og_url":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2018-04-23T16:46:20+00:00","article_modified_time":"2025-06-14T03:15:00+00:00","og_image":[{"width":1500,"height":679,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/04\/graphql-nodejs.png","type":"image\/png"}],"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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Create a GraphQL Application With Node.js, NoSQL Databases","datePublished":"2018-04-23T16:46:20+00:00","dateModified":"2025-06-14T03:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/"},"wordCount":1265,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["API","graphql","javascript","NoSQL Database"],"articleSection":["Application Design","Couchbase Server","JavaScript","Node.js","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/","url":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/","name":"Creating a GraphQL Application With Node.js and a NoSQL Database","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2018-04-23T16:46:20+00:00","dateModified":"2025-06-14T03:15:00+00:00","description":"Learn GraphQL for querying in a NoSQL Node.js database application that's built for Couchbase. You'll also learn when to use GraphQL, and when not to.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create a GraphQL Application With Node.js, NoSQL Databases"}]},{"@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":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@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":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354","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\/author\/nic-raboy-2\/"}]}},"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","author_category":"","last_name":"Raboy","first_name":"Nic","job_title":"","user_url":"https:\/\/www.thepolyglotdeveloper.com","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."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/5036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=5036"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/5036\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=5036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=5036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=5036"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=5036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}