Skip to content

Instantly share code, notes, and snippets.

@sultaniman
sultaniman / ecto-helpers.ex
Created April 28, 2019 12:39
Ecto helpers
defmodule Idp.EctoHelpers do
alias Ecto.Changeset
@doc """
Transform `%Ecto.Changeset{}` errors to a map
containing field name as a key on which validation
error happened and it's formatted message.
For example:
@sultaniman
sultaniman / common-changeset-error.ex
Created April 28, 2019 12:33
Common changeset error
{
:error,
%{
message: "Changeset errors occurred",
code: :changeset_errors,
errors: [
%{field: "error message"}
]
}
}
@sultaniman
sultaniman / common-absinthe-error-shape.ex
Created April 28, 2019 12:23
Common Absinthe error shape
@permission_denied {
:error,
%{
message: gettext("Permission denied"),
code: :permission_denied
}
}
@sultaniman
sultaniman / declarative-schemas.py
Created November 29, 2018 10:52
Just sketching for declarative schemas
def add(field_name, type, **options):
pass
def create_index(field_name):
pass
def schema(table_name, *actions):
return DatabaseTable(table_name)
from typing import Any, Dict
from graphene_django.views import GraphQLView
from graphql.error import GraphQLError
from graph.format_error import format_error
class MyGraphQLView(GraphQLView):
@staticmethod
from typing import Dict, Any
from graphql import GraphQLError
def format_error(error: GraphQLError) -> Dict[str, Any]:
"""Extract field from ``error`` and return formatted error
:param error: GraphQLError
:return: mapping of fieldName -> error message
"""
import Vue from 'vue'
import VueApollo from 'vue-apollo'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { GRAPHQL_ENDPOINT } from './config'
const httpLink = new HttpLink({
// You should use an absolute URL here
uri: GRAPHQL_ENDPOINT
module.exports = {
chainWebpack: config => {
config.module
.rule('graphql')
.test(/\.gql$/)
.use('graphql-tag/loader')
.loader('graphql-tag/loader')
.end()
}
}
const path = require('path')
const {
hasYarn,
IpcMessenger,
} = require('@vue/cli-shared-utils')
const chalk = require('chalk')
const { defaultValue, nullable } = require('./utils')
const DEFAULT_SERVER_FOLDER = './apollo-server'
const COMMAND_OPTIONS = {
function posix-source
for i in (cat $argv)
set arr (echo $i |tr = \n)
set -gx $arr[1] $arr[2]
end
end