This file contains 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
defmodule DemoApp.User do | |
def get_user() do | |
with {:ok, user} <- Repo.query(%User{}), | |
{:ok, ^user} <- is_user_email_verified(user), | |
{:ok, ^user} <- is_user_subscribed(user) do | |
{:ok, user} | |
else | |
{:error, reason} -> {:err, reason} | |
_ -> {:error, "Something went wrong"} | |
end |
This file contains 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
version: "3" | |
services: | |
elasticsearch: | |
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0 | |
environment: | |
- cluster.name=elasticsearch-oss | |
- discovery.type=single-node | |
- cluster.routing.allocation.disk.threshold_enabled=false | |
- bootstrap.memory_lock=true | |
- http.cors.enabled=true |
This file contains 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
FROM nginx:latest | |
RUN echo "upstream php { server wordpress:9000; }" > /etc/nginx/conf.d/upstream.conf | |
COPY default.conf /etc/nginx/conf.d/default.conf |
This file contains 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
import jwt from "jsonwebtoken"; | |
import User from "@server/models/user_model"; | |
const PRODUCTION = process.env.NODE_ENV === "production"; | |
export default (options) => async (req, res, next) => { | |
const refreshToken = req.cookies["refresh_token"]; | |
const accessToken = req.cookies["access_token"]; | |
const csrfHeader = req.get("X-Csrf-Token"); |
This file contains 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 server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
schemaDirectives: { | |
requireAuth: requireAuthDirective | |
} | |
}); |
This file contains 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 { | |
SchemaDirectiveVisitor, | |
AuthenticationError | |
} = require("apollo-server"); | |
class RequireAuthDirective extends SchemaDirectiveVisitor { | |
visitFieldDefinition(field) { | |
const { resolve = defaultFieldResolver } = field; | |
const { role } = this.args; | |
field.resolve = async function(...args) { |
This file contains 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"); | |
const mockPosts = [ | |
{ id: 1, title: "Helvetica and Times New Roman walk into a bar. Get out of here! shouts the bartender. We don't serve your type!", ownerId: 1 }, | |
{ id: 2, title: "Why do we tell actors to break a leg? Because every play has a cast.", ownerId: 2 }, | |
{ id: 3, title: "Did you hear about the mathematician who’s afraid of negative numbers? He'll stop at nothing to avoid them.", ownerId: 1 } | |
]; | |
module.exports.postDefs = gql` | |
extend type Query { |
This file contains 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"); | |
const _ = require("lodash"); | |
const { postDefs, postResolvers } = require("./models/post.js"); | |
module.exports.typeDefs = gql` | |
enum Role { | |
ADMIN | |
USER | |
} |
This file contains 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 path = require("path"); | |
const chokidar = require("chokidar"); | |
const reload = require("require-reload")(require); | |
let server = reload("./src/app.js"); | |
const srcDir = path.resolve(__dirname, "src"); | |
const watcher = chokidar.watch(srcDir + "/**/*.js", {}); | |
watcher.on("ready", () => | |
server |
This file contains 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 { ApolloServer } = require("apollo-server"); | |
const { typeDefs, resolvers } = require("./schema.js"); | |
const requireAuthDirective = require("./directives/requireAuthDirective"); | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
schemaDirectives: { | |
requireAuth: requireAuthDirective | |
}, |
NewerOlder