This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require(`mongoose`); | |
let employeeSchema = new mongoose.Schema({ | |
firstName: { | |
type: String, | |
default: "" | |
}, | |
lastName: { | |
type: String, | |
default: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imported the employee model from the models directory | |
const models = require(`../models/index`); | |
const employeeResolvers = { | |
Query: { | |
/** | |
* This method will return an array of employees according to the query | |
*/ | |
employees: (root, args, context, info) => { | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { gql } = require('apollo-server-express'); | |
const employeeType = gql` | |
# Defined the query type | |
type Query { | |
employees: [employee!] | |
employee(id: ID!): employee | |
} | |
# Defined the mutation type | |
type Mutation { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imported a message type | |
const messageType = require(`./message.type`); | |
// Imported a employee type | |
const employeeType = require(`./employee.type`) | |
// Both the types are indexed and combined into an array | |
const typeDefs = [messageType, employeeType]; | |
// Exported the typedefs to entry file | |
module.exports = { typeDefs }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const mongoose = require(`mongoose`); | |
const { ApolloServer } = require('apollo-server-express'); | |
// Imported the typeders and resolver | |
const { typeDefs } = require( `./typedefs`); | |
const { resolvers } = require( `./resolvers`); | |
// Created a instance of Apollo server with typedefs and resolvers. | |
const server = new ApolloServer({typeDefs, resolvers}); | |
const app = express(); | |
(async () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const { ApolloServer, gql } = require('apollo-server-express'); | |
// This is the schema types | |
const typeDefs = gql` | |
type Query { | |
hello: String | |
} | |
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"net/http" | |
) | |
func ParseBody(r *http.Request, x interface{}) { | |
if body, err := ioutil.ReadAll(r.Body); err == nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import ( | |
"github.com/example/simple-REST/pkg/config" | |
"github.com/jinzhu/gorm" | |
) | |
var db *gorm.DB | |
type Book struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
import ( | |
"github.com/jinzhu/gorm" | |
_ "github.com/jinzhu/gorm/dialects/mysql" | |
) | |
var ( | |
db * gorm.DB | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import ( | |
"encoding/json" | |
"fmt" | |
"github.com/example/simple-REST/pkg/utils" | |
"github.com/gorilla/mux" | |
"net/http" | |
"strconv" | |
"github.com/example/simple-REST/pkg/models" |
NewerOlder