GraphQL has been a buzzword for last few years after Facebook has made it open-source and so I tried GraphQL with the Node.js and I completely agree with all the buzz about the GraphQL, its advantages, and simplicity. I recently switched to Go-lang for the new project from the Node.js and I decided to try GraphQL with the Go-lang. There are not many library options with the Go-lang but I have tried it with these 4 libraries. , , , and . And I have to say that is winning all the ground in all libraries I have tried. Thunder graphql graphql-go gqlgen gqlgen is still in the beta with latest version at the time of writing this article and it’s rapidly evolving. You can find their road-map . And as now are officially sponsoring them so we will see even better development speed for this awesome opensource project. and are major contributors of this and also wrote the before. gqlgen v0.4.4 here 99designs vektah neelance neelance graphql-go So let’s dive into the library semantic assuming you have basic knowledge. graphql Highlights As their headline states This is a library for quickly creating strictly typed graphql servers in golang. I think this is the most promising thing about a library that you will never see here as it uses strictly typed approach. map[string]interface{} Apart from that, it uses : So you define your API using the graphql and has its own powerful code generation tools which will auto-generate all of your GraphQL code and you will just need to implement the core logic of that interface methods. Schema first Approach Schema Definition Language This version has now been deprecated. Please follow this articles for latest updates. https://medium.freecodecamp.org/deep-dive-into-graphql-with-golang-d3e02a429ac3 Code As it’s schema-first approach so let’s quickly define a schema. We are taking job application forum as an example. Now library provide codegen command which will generate all the required files for project files gqlgen init gqlgen.yml — The gqlgen config file, knobs for controlling the generated code. generated.go — The graphql execution runtime, the bulk of the generated code models_gen.go — Generated models required to build the graph. Often you will override these with models you write yourself. Still very useful for input types. resolver.go — This is where your application code lives. generated.go will call into this to get the data the user has requested. As the docs stats if you don’t provide the models definition it will auto-generate the models but in most of the cases you will write your own model as you will have more fine-grained control on data types and you can use third-party structs when needed(Like you can use AWS or any other library’s Struct for like credential, config, etc). So let’s override generate file: gqlgen.yml Here we have given the path of all the models. In file we have defined one custom scalar so we need to tell graphql about how to Marshal and Unmarshal them. schema.graphql Timestamp Here is our file where all above structs are defined: models.go Now if you have noticed we haven’t defined any struct for but only Marshal and Unmarshal methods for Timestamp. So the library handles this for you just need to write these two methods. Timestamp Another important thing to notice is we haven’t defined a struct for inputs( and ) too. So as promised by the library it will be auto-generated in as per the given config in file with a notice that you should not edit this file. NewJob NewApplication models/inputs.go gqlgen.yml Now, let’s come to the most important file and that is , which has all the magic code written its very long file obviously but let’s have a look at needed code from it. generated.go Another file generated by gqlgen is which is the file where you will put all of your logic. Following is auto-generated stub file(Little edited for comments, formatting and package change) resolver.go Now all you need to do is write your logic in these methods. I am writing one sample method to create and get all jobs with the help of Firebase real-time database. and cutting down the database code for the sake of he length of this article which you can find . here Now let’s try this out and hit the servers and run first mutation $ go run server/server.go As we can see one job is created under Position’s node(as configured in database layer) and we get the same response in graphql also with newly created id. Now let’s test query: But wait, WHAATT! We got an error. Don’t panic its because graphql don’t understand how to fetch User object from just a userId so we need to implement resolver method for that which currently states that . CreatedBy CreatedBy panic(**“not implemented”**) So now hit the query again: And it’s all working. Now What? This article just gives a basic demo of how graphql server can be implemented in the golang(I know there can be many changes in the code and structure). This code is on . I will write article soon to add CORS, Validation, Authentication, and Configuration with Golang gqlgen server. Till then happy coding. Github Part-2 is on the way! Thanks for reading! (A few 👏 are always appreciated. 😀)