{"id":5089,"date":"2018-05-08T09:00:31","date_gmt":"2018-05-08T16:00:31","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=5089"},"modified":"2025-06-13T18:45:29","modified_gmt":"2025-06-14T01:45:29","slug":"using-graphql-with-golang-and-a-nosql-database","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/","title":{"rendered":"Using GraphQL with Golang and a NoSQL Database"},"content":{"rendered":"<p>A few weeks ago I had mentioned that I was learning about the increasingly popular GraphQL and how it can be a replacement to the common RESTful API. In my <a href=\"https:\/\/www.couchbase.com\/blog\/creating-a-graphql-application-with-node-js-and-a-nosql-database\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous example<\/a>, we saw how to create a GraphQL application using Node.js and a <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a> <a href=\"https:\/\/www.couchbase.com\/resources\/why-nosql\">NoSQL database<\/a>. However, I&#8217;m just as much a fan of the Go programming language as I am of Node.js.<\/p>\n<p>We&#8217;re going to see how to create an application with Golang that can create and query for data using <a href=\"https:\/\/www.couchbase.com\/blog\/processing-graphql-queries-with-java-spring-boot-and-nosql\/\">GraphQL queries<\/a> rather than several RESTful API endpoints.<\/p>\n<p><!--more--><\/p>\n<p>If you&#8217;re unfamiliar with GraphQL, it works by passing queries from a front-end to the backend and getting back only the data that you&#8217;ve requested, regardless on where it came from or how complex, rather than consuming data from any number of potentially unrelated API endpoints. This reduces your requests as well as your data payload, keeping things quick and efficient.<\/p>\n<h2>Getting Started with GraphQL and Golang<\/h2>\n<p>Like with a RESTful API, most of a GraphQL application will consist of setup. However, less of a GraphQL application will depend on planning, which is different from a RESTful API which requires heavy planning in order to remain easy to use.<\/p>\n<p>We need to install a GraphQL package dependency for Golang before we can proceed. From the command line, execute the following:<\/p>\n<pre class=\"lang:default decode:true \">go get github.com\/graphql-go\/graphql<\/pre>\n<p>With our dependency available, create a new project within your\u00a0<strong>$GOPATH<\/strong>. Within that project, create a file called\u00a0<strong>main.go<\/strong> and include the following which will be our application base:<\/p>\n<pre class=\"lang:default decode:true \">package main\r\n\r\nimport (\r\n\t\"encoding\/json\"\r\n\t\"fmt\"\r\n\t\"log\"\r\n\t\"net\/http\"\r\n\t\"github.com\/graphql-go\/graphql\"\r\n)\r\n\r\ntype Account struct {\r\n\tID        string `json:\"id,omitempty\"`\r\n\tFirstname string `json:\"firstname\"`\r\n\tLastname  string `json:\"lastname\"`\r\n\tType      string `json:\"type\"`\r\n}\r\n\r\ntype Blog struct {\r\n\tID      string `json:\"id,omitempty\"`\r\n\tAccount string `json:\"account\"`\r\n\tTitle   string `json:\"title\"`\r\n\tContent string `json:\"content\"`\r\n\tType    string `json:\"type\"`\r\n}\r\n\r\nfunc main() {\r\n\tfmt.Println(\"Starting application...\")\r\n\taccountType := graphql.NewObject(graphql.ObjectConfig{\r\n\t\tName: \"Account\",\r\n\t\tFields: graphql.Fields{},\r\n\t})\r\n\tblogType := graphql.NewObject(graphql.ObjectConfig{\r\n\t\tName: \"Blog\",\r\n\t\tFields: graphql.Fields{},\r\n\t})\r\n\trootQuery := graphql.NewObject(graphql.ObjectConfig{\r\n\t\tName: \"Query\",\r\n\t\tFields: graphql.Fields{},\r\n\t})\r\n\trootMutation := graphql.NewObject(graphql.ObjectConfig{\r\n\t\tName: \"RootMutation\",\r\n\t\tFields: graphql.Fields{},\r\n\t})\r\n\tschema, _ := graphql.NewSchema(graphql.SchemaConfig{\r\n\t\tQuery:    rootQuery,\r\n\t\tMutation: rootMutation,\r\n\t})\r\n\thttp.HandleFunc(\"\/graphql\", func(w http.ResponseWriter, r *http.Request) {\r\n\t\tresult := graphql.Do(graphql.Params{\r\n\t\t\tSchema:        schema,\r\n\t\t\tRequestString: r.URL.Query().Get(\"query\"),\r\n\t\t})\r\n\t\tjson.NewEncoder(w).Encode(result)\r\n\t})\r\n\thttp.ListenAndServe(\":8080\", nil)\r\n}<\/pre>\n<p>Our plan is to create an application that can create and query accounts as well as create and query blog entries for any particular account. The data model for our application is defined by the\u00a0<code>Account<\/code> struct and the <code>Blog<\/code> struct. This data model will help power our database data model as well as our GraphQL data model.<\/p>\n<p>When it comes to the GraphQL setup, you&#8217;ll notice that there are a few objects created. The <code>accountType<\/code> and the <code>blogType<\/code> represent the GraphQL data model which will be crafted around the Go structs. They are not yet configured, but they will be. The <code>rootQuery<\/code> will be the set of queries we can run and the <code>rootMutation<\/code> will be any data changing mutation that can be run. With GraphQL, you&#8217;re not limited to just reading data.<\/p>\n<p>The GraphQL schema allows us to define what are queries and what are mutations. This is required for when we wish to consume queries. Even though we&#8217;re not creating a RESTful API, we still need an HTTP endpoint. This single <code>\/graphql<\/code> endpoint will handle all querying and mutations and is powered by the schema.<\/p>\n<p>Before we hook up the database, we can define our GraphQL schema:<\/p>\n<pre class=\"lang:default decode:true \">accountType := graphql.NewObject(graphql.ObjectConfig{\r\n    Name: \"Account\",\r\n    Fields: graphql.Fields{\r\n        \"id\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n        \"firstname\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n        \"lastname\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n    },\r\n})\r\nblogType := graphql.NewObject(graphql.ObjectConfig{\r\n    Name: \"Blog\",\r\n    Fields: graphql.Fields{\r\n        \"id\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n        \"account\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n        \"title\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n        \"content\": &amp;graphql.Field{\r\n            Type: graphql.String,\r\n        },\r\n    },\r\n})<\/pre>\n<p>Notice that we&#8217;re only defining property names and their corresponding data type. I told you it would be pretty similar to how we&#8217;ve defined the data structures in Go.<\/p>\n<p>Now let&#8217;s focus on loading our schema with data from Couchbase Server.<\/p>\n<h2>Querying Data from a NoSQL Database with GraphQL<\/h2>\n<p>As of right now we&#8217;ve done no database preparation. The point of this tutorial is not around configuring Couchbase. You&#8217;ll need Couchbase Server available with N1QL support, a Bucket, some indexes, and a role-based access control account for the application.<\/p>\n<p>From the command line, execute the following lines to get our database packages:<\/p>\n<pre class=\"lang:default decode:true \">go get github.com\/satori\/go.uuid\r\ngo get gopkg.in\/couchbase\/gocb.v1<\/pre>\n<p>The above commands will get us a package for creating UUID values for document keys as well as the Couchbase Go SDK.<\/p>\n<p>Ignoring everything we&#8217;ve already done to our\u00a0<strong>main.go<\/strong> file, take a look at the following code and fit it into what you have where it makes sense:<\/p>\n<pre class=\"lang:default decode:true\">package main\r\n\r\nimport (\r\n\t\"encoding\/json\"\r\n\t\"fmt\"\r\n\t\"log\"\r\n\t\"net\/http\"\r\n\t\"github.com\/graphql-go\/graphql\"\r\n\tuuid \"github.com\/satori\/go.uuid\"\r\n\tgocb \"gopkg.in\/couchbase\/gocb.v1\"\r\n)\r\n\r\nvar bucket *gocb.Bucket\r\n\r\nfunc main() {\r\n\tfmt.Println(\"Starting application...\")\r\n\tcluster, err := gocb.Connect(\"couchbase:\/\/localhost\")\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\tcluster.Authenticate(gocb.PasswordAuthenticator{Username: \"example\", Password: \"123456\"})\r\n\tbucket, err = cluster.OpenBucket(\"example\", \"\")\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n}<\/pre>\n<p>Notice that we have defined a Bucket that we&#8217;ll be using when interacting with the database. We&#8217;re connecting to a Couchbase cluster in the <code>main<\/code> function, authenticating with an RBAC account, and opening a Bucket, all of which should have been defined prior to starting this tutorial.<\/p>\n<p>Let&#8217;s assume you&#8217;ve already got data in your database. We&#8217;re going to start by trying to query for data. Remember the following chunk of code that was previously added?<\/p>\n<pre class=\"lang:default decode:true \">rootQuery := graphql.NewObject(graphql.ObjectConfig{\r\n    Name: \"Query\",\r\n    Fields: graphql.Fields{ },\r\n})<\/pre>\n<p>Each field will exist as a field in the <code>Fields<\/code> property. Let&#8217;s say we want to get all the accounts from our database.<\/p>\n<pre class=\"lang:default decode:true \">\"accounts\": &amp;graphql.Field{\r\n    Type: graphql.NewList(accountType),\r\n    Resolve: func(p graphql.ResolveParams) (interface{}, error) {\r\n        query := gocb.NewN1qlQuery(\"SELECT META(account).id, account.* FROM example AS account WHERE account.type = 'account'\")\r\n        rows, err := bucket.ExecuteN1qlQuery(query, nil)\r\n        if err != nil {\r\n            return nil, err\r\n        }\r\n        var accounts []Account\r\n        var row Account\r\n        for rows.Next(&amp;row) {\r\n            accounts = append(accounts, row)\r\n        }\r\n        return accounts, nil\r\n    },\r\n},<\/pre>\n<p>In the above code we&#8217;re creating a GraphQL field called <code>accounts<\/code> that will return a list of <code>accountType<\/code> when executed. The <code>Resolve<\/code> function is what does the heavy lifting. We can optionally pass query parameters, but for this particular field we are not. When trying to query for accounts, we are creating a N1QL query that returns all possible properties and results. The GraphQL query will determine which of those properties and results make it to the client.<\/p>\n<p>Take the following front-end query that can be executed:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n    accounts {\r\n        id,\r\n        firstname\r\n    }\r\n}<\/pre>\n<p>While we could get the <code>id<\/code>, <code>firstname<\/code>, and <code>lastname<\/code>, we are choosing to only get the <code>id<\/code> and <code>firstname<\/code> of our results. To actually run the query, we&#8217;d issue a cURL statement like this:<\/p>\n<pre class=\"lang:default decode:true \">curl -g 'https:\/\/localhost:8080\/graphql?query={accounts{id,firstname}}'<\/pre>\n<p>Remember, our GraphQL query is sent view the query parameters to our API endpoint.<\/p>\n<p>Let&#8217;s look at another possible GraphQL query. Let&#8217;s say we want to query for a particular account, not all accounts. We could create a field like the following:<\/p>\n<pre class=\"lang:default decode:true \">\"account\": &amp;graphql.Field{\r\n    Type: accountType,\r\n    Args: graphql.FieldConfigArgument{\r\n        \"id\": &amp;graphql.ArgumentConfig{\r\n            Type: graphql.NewNonNull(graphql.String),\r\n        },\r\n    },\r\n    Resolve: func(params graphql.ResolveParams) (interface{}, error) {\r\n        var account Account\r\n        account.ID = params.Args[\"id\"].(string)\r\n        _, err := bucket.Get(account.ID, &amp;account)\r\n        if err != nil {\r\n            return nil, err\r\n        }\r\n        return account, nil\r\n    },\r\n},<\/pre>\n<p>This field when queried will return a single <code>accountType<\/code>, but there are arguments that can be passed. We&#8217;re requiring that an <code>id<\/code> be present and we&#8217;re requiring that it be a string. In the <code>Resolve<\/code>, we can get the <code>id<\/code> parameter and use it to get a NoSQL document by the document key. The result is returned and the GraphQL query determines what properties are sent back to the client.<\/p>\n<p>Take the following query:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n    account(id:\"2345345435\") {\r\n        firstname,\r\n        lastname\r\n    }\r\n}<\/pre>\n<p>In the above query, we pass an ID and choose to only return the <code>firstname<\/code> and <code>lastname<\/code> of the results. To actually run this query, we can issue a cURL statement like the following:<\/p>\n<pre class=\"lang:default decode:true \">curl -g 'https:\/\/localhost:8080\/graphql?query={account(id:\"2345345435\"){firstname,lastname}}'<\/pre>\n<p>Now let&#8217;s say that we want to return all blogs for a particular user account. The steps will be similar to what we saw when querying for a particular account. The following would exist as a field in our <code>rootQuery<\/code>:<\/p>\n<pre class=\"lang:default decode:true \">\"blogs\": &amp;graphql.Field{\r\n    Type: graphql.NewList(blogType),\r\n    Args: graphql.FieldConfigArgument{\r\n        \"account\": &amp;graphql.ArgumentConfig{\r\n            Type: graphql.NewNonNull(graphql.String),\r\n        },\r\n    },\r\n    Resolve: func(params graphql.ResolveParams) (interface{}, error) {\r\n        account := params.Args[\"account\"].(string)\r\n        query := gocb.NewN1qlQuery(\"SELECT META(blog).id, blog.* FROM example AS blog WHERE blog.type = 'blog' AND blog.account = $1\")\r\n        var n1qlParams []interface{}\r\n        n1qlParams = append(n1qlParams, account)\r\n        rows, err := bucket.ExecuteN1qlQuery(query, n1qlParams)\r\n        if err != nil {\r\n            return nil, err\r\n        }\r\n        var blogs []Blog\r\n        var row Blog\r\n        for rows.Next(&amp;row) {\r\n            blogs = append(blogs, row)\r\n        }\r\n        return blogs, nil\r\n    },\r\n},<\/pre>\n<p>The result will be a list of <code>blogType<\/code> and we&#8217;re expecting a required <code>account<\/code> parameter to be passed in string format. Inside the <code>Resolve<\/code> function we can get the <code>account<\/code> value and use it in a parameterized N1QL query. The query will return all blog entries only for a particular account based on the <code>account<\/code> value.<\/p>\n<p>The query for getting all blogs might look like the following:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n    blogs(account:\"2345345435\") {\r\n        id,\r\n        title\r\n    }\r\n}<\/pre>\n<p>The above looks pretty similar to what we saw when querying for a particular account. We&#8217;re expecting a variable and we&#8217;re choosing to only return the <code>id<\/code> and the <code>title<\/code> properties.<\/p>\n<p>Want to see a pretty neat query based on what we have so far? Check out the following query:<\/p>\n<pre class=\"lang:default decode:true \">{\r\n    account(id:\"2345345435\") {\r\n        firstname,\r\n        lastname\r\n    }\r\n    blogs(account:\"2345345435\") {\r\n        title,\r\n        content\r\n    }\r\n}<\/pre>\n<p>In the above example we&#8217;re making a single request. It is a single query, but we&#8217;re asking for account data and blog data for a particular account. Had we done this with a RESTful API we would have made several requests to our server and made potential application level mutations.<\/p>\n<p>The cURL command would look like this:<\/p>\n<pre class=\"lang:default decode:true \">curl -g 'https:\/\/localhost:8080\/graphql?query={account(id:\"2345345435\"){firstname,lastname}blogs(account:\"2345345435\"){title,content}}'<\/pre>\n<p>Up until now we&#8217;ve only done read queries. How about if we wanted to do a mutation where we create or alter data?<\/p>\n<p>Let&#8217;s take a look at data mutations with GraphQL.<\/p>\n<p>Instead of working in the <code>rootQuery<\/code>, we&#8217;re going to work in the <code>rootMutation<\/code>. For fields, add the following:<\/p>\n<pre class=\"lang:default decode:true \">\"createAccount\": &amp;graphql.Field{\r\n    Type: accountType,\r\n    Args: graphql.FieldConfigArgument{\r\n        \"firstname\": &amp;graphql.ArgumentConfig{\r\n            Type: graphql.NewNonNull(graphql.String),\r\n        },\r\n        \"lastname\": &amp;graphql.ArgumentConfig{\r\n            Type: graphql.NewNonNull(graphql.String),\r\n        },\r\n    },\r\n    Resolve: func(params graphql.ResolveParams) (interface{}, error) {\r\n        var account Account\r\n        account.Firstname = params.Args[\"firstname\"].(string)\r\n        account.Lastname = params.Args[\"lastname\"].(string)\r\n        account.Type = \"account\"\r\n        id, _ := uuid.NewV4()\r\n        _, err := bucket.Insert(id.String(), &amp;account, 0)\r\n        if err != nil {\r\n            return nil, err\r\n        }\r\n        account.ID = id.String()\r\n        return account, nil\r\n    },\r\n},<\/pre>\n<p>Notice that we&#8217;re returning an <code>accountType<\/code> and that we&#8217;re expecting two parameters to be passed with our query. However, the strategy really isn&#8217;t any different.<\/p>\n<p>In the <code>Resolve<\/code> function we&#8217;re obtaining our parameters and using them to create a new account in the database. Because this is linked to our schema as a mutation, we are querying differently.<\/p>\n<p>First, here is the query we&#8217;d want to run:<\/p>\n<pre class=\"lang:default decode:true \">mutation+_ {\r\n    createAccount(firstname:\"Matt\",lastname:\"Groves\") {\r\n        id,\r\n        firstname,\r\n        lastname\r\n    }\r\n}<\/pre>\n<p>Notice that we&#8217;re prefixing with the word <code>mutation<\/code>. In cURL, it would look like the following:<\/p>\n<pre class=\"lang:default decode:true \">curl -g 'https:\/\/localhost:8080\/graphql?query=mutation+_{createAccount(firstname:\"Matt\",lastname:\"Groves\"){id,firstname,lastname}}'<\/pre>\n<p>Now I could go ahead and continue creating fields that do querying or mutations, but the steps are the same. I&#8217;ll leave it to your imagination to continue contributing to this particular application idea.<\/p>\n<h2>Conclusion<\/h2>\n<p>You just saw how to use <a href=\"https:\/\/graphql.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">GraphQL<\/a> to query for data in a Golang application that uses a <a href=\"https:\/\/www.couchbase.com\/resources\/why-nosql\">NoSQL database<\/a>. GraphQL is very useful if you want to let the user define what data they want in a single request rather than tirelessly creating multiple RESTful API endpoints that the user must keep track of. It is important to note that GraphQL is not a replacement when it comes to your application querying your database. You&#8217;ll still need to create proper N1QL queries in <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a>. GraphQL only operates from a client level.<\/p>\n<p>For more information on using Go with Couchbase, check out the <a href=\"https:\/\/developer.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Developer Portal<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I had mentioned that I was learning about the increasingly popular GraphQL and how it can be a replacement to the common RESTful API. In my previous example, we saw how to create a GraphQL application [&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,1815,1816,1820,1812],"tags":[2210,1725],"ppma_author":[9032],"class_list":["post-5089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-best-practices-and-tutorials","category-couchbase-server","category-golang","category-n1ql-query","tag-graphql","tag-nosql-database"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using GraphQL with Golang and a NoSQL Database<\/title>\n<meta name=\"description\" content=\"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.\" \/>\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\/using-graphql-with-golang-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=\"Using GraphQL with Golang and a NoSQL Database\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-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-05-08T16:00:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T01:45:29+00:00\" \/>\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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Using GraphQL with Golang and a NoSQL Database\",\"datePublished\":\"2018-05-08T16:00:31+00:00\",\"dateModified\":\"2025-06-14T01:45:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\"},\"wordCount\":1481,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"graphql\",\"NoSQL Database\"],\"articleSection\":[\"Application Design\",\"Best Practices and Tutorials\",\"Couchbase Server\",\"GoLang\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\",\"name\":\"Using GraphQL with Golang and a NoSQL Database\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2018-05-08T16:00:31+00:00\",\"dateModified\":\"2025-06-14T01:45:29+00:00\",\"description\":\"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-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\/using-graphql-with-golang-and-a-nosql-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using GraphQL with Golang and a NoSQL Database\"}]},{\"@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":"Using GraphQL with Golang and a NoSQL Database","description":"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.","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\/using-graphql-with-golang-and-a-nosql-database\/","og_locale":"en_US","og_type":"article","og_title":"Using GraphQL with Golang and a NoSQL Database","og_description":"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.","og_url":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2018-05-08T16:00:31+00:00","article_modified_time":"2025-06-14T01:45:29+00:00","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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Using GraphQL with Golang and a NoSQL Database","datePublished":"2018-05-08T16:00:31+00:00","dateModified":"2025-06-14T01:45:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/"},"wordCount":1481,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["graphql","NoSQL Database"],"articleSection":["Application Design","Best Practices and Tutorials","Couchbase Server","GoLang","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/","url":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/","name":"Using GraphQL with Golang and a NoSQL Database","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2018-05-08T16:00:31+00:00","dateModified":"2025-06-14T01:45:29+00:00","description":"Learn how to create a web application using the Go programming language and a Couchbase NoSQL database that can be queried using GraphQL from the front-end.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-and-a-nosql-database\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/using-graphql-with-golang-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\/using-graphql-with-golang-and-a-nosql-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using GraphQL with Golang and a NoSQL Database"}]},{"@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\/5089","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=5089"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/5089\/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=5089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=5089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=5089"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=5089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}