Skip to content

Instantly share code, notes, and snippets.

View tricoder42's full-sized avatar
🕴️
I may be slow to respond.

tricoder42

🕴️
I may be slow to respond.
View GitHub Profile
@tricoder42
tricoder42 / 03_fetchSaga.full.js
Created June 13, 2017 07:58
2017/06/13 [Medium] redux-saga factories and decorators
export const fetchSaga = (entity, api) => function* ({ payload }) {
try {
const data = yield call(api, payload)
yield put(entity.response(data))
}
catch(error) {
// When there's error.response, it's usually response from
// backend server with status 4xx or 5xx.
// No response mostly means there's a connection error, because
// we don't even get anything from server.
@tricoder42
tricoder42 / 05_auth.js
Created June 13, 2017 08:10
2017/06/13 [Medium] redux-saga factories and decorators
// Just an example of `isAuthenticated` selector
const selector = {
isAuthenticated: state => state.auth.isAuthenticated
}
export const authRequired = (saga) => function* (action) {
const isAuthenticated = yield select(selector.isAuthenticated)
// If user isn't authenticated, redirect him to /login
if (!isAuthenticated) {
@tricoder42
tricoder42 / bundle.js
Last active June 23, 2017 16:49
Removing development files from bundle
// load() call is removed, but import remains there
!function(modules) {
function __webpack_require__(moduleId) {
if (installedModules[moduleId]) return installedModules[moduleId].exports;
var module = installedModules[moduleId] = {
i: moduleId,
l: !1,
exports: {}
};
@tricoder42
tricoder42 / lingui_format.json
Created September 1, 2017 18:36
jsLingui message catalog formats
{
"Edit": {
"translation": "Upravit",
"origin": [
[
"src/lingui/projects/scenes/Repository/ui/EditableDescription.js",
81
]
]
},
@tricoder42
tricoder42 / schema.py
Created September 8, 2017 09:38
GraphQL in Python - Concept
class ProjectType(graphql.DjangoModel):
class Meta:
model = Project
class ProjectSchema(graphql.DetailQuery,
graphql.ListQuery,
graphql.CreateMutation,
graphql.UpdateMutation,
graphql.DeleteMutation,
@tricoder42
tricoder42 / 00_GraphQL_Subscriptions.md
Last active February 22, 2023 12:40
GraphQL Subscriptions with django-channels

GraphQL Subscription with django-channels

Django channels are official way for implementing async messaging in Django.

The primary caveat when working with GraphQL subscription is that we can't serialize message before broadcasting it to Group of subscribers. Each subscriber might use different GraphQL query so we don't know how to serialize instance in advance.

See related issue

GraphQL example

Graphene Tutorial

Example of authentication mutations and user queries in GraphQL API.

const flip = () => ({
flipResults: Math.random()
})
// creation of headlesscomponent
class CoinFlip extends React.Component {
state = flip()
handleClick = () => this.setState(flip)
api() {
@tricoder42
tricoder42 / deprecate.js
Created August 25, 2018 13:42
Deprecate renamed packages on NPM and update their READMEs
/*
Usage: node ./deprecate.js OTP_TOKEN
OTP_TOKEN is used for 2FA
*/
const path = require("path")
const fs = require("fs-extra")
const { exec } = require("child_process")
  1. Query projectIssue is resolved with an object "IssueType:18"
  2. Mutation issueEdit is called and returns the same object with updated attachments
  3. Object "IssueType:18" is updated correctly in cache (checked in Apollo DevTool and also manually by store.readFragment)
  4. Query projectIssue reloaded from cache automatically, but this this it doesn't return object

In Apollo DevTool I see this field in root query: issue({"issueId":"18","project":"IEP001"}): IssueType:18. I believe the query should be updated when object IssueType:18 in cache is updated, but when it happens, the object is empty.