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
-- This is one technique for batching up the *first* page of results when doing pagination. | |
-- Potentially useful when using GraphQL and Dataloader. | |
-- | |
-- In this example, we return the first 10 books whose author_id is 1,2,3,4 or 5 and genre | |
-- is "biography", ordered by "title" | |
-- | |
-- For cursor-based (keyset) pagination, this technique won't work for anything after the | |
-- first "page", because the where clause needs to be the same for every entry in the | |
-- batch, which means you can't use different cursors. In practice, there isn't usually a | |
-- need to batch up subsequent pages, because your "next page" GQL queries will typically |
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 * as React from "react"; | |
import { graphql, usePreloadedQuery } from "react-relay"; | |
import { Button, Heading, Stack, Text } from "native-base"; | |
import { ProfileScreenQuery } from "~/__generated__/ProfileScreenQuery.graphql"; | |
import useLogout from "~/hooks/useLogout"; | |
import { TabParamListProps } from "~/navigation-types"; | |
import withData, { IScreenContainerProps } from "~/utils/withData"; |
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 typing import Generic, TypeVar | |
import strawberry | |
ConnectionNode = TypeVar("ConnectionNode") | |
@strawberry.type | |
class Edge(Generic[ConnectionNode]): | |
node: ConnectionNode |
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 django.contrib import admin | |
from django.db.models import Count, F | |
class FilterCountMixin(admin.SimpleListFilter): | |
def __init__(self, request, params, model, model_admin): | |
# Store the request so we can reapply all the filters properly later | |
self.request = request | |
super().__init__(request, params, model, model_admin) | |
def get_filter_counts_parameter_name(self): |
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 django.db import transaction | |
from django.db import models | |
from django.db.models.signals import post_save | |
def on_save(obj: models.Model, callback, on_commit=False): | |
""" | |
Attaches a one-off callback that's triggered after a Django model instance is | |
saved. Optionally makes use of transaction.on_commit to defer until any wrapping | |
transaction has also committed. |
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 React from "react"; | |
import { graphql } from "react-relay"; | |
import createPageContainer from "../relay/createPageContainer"; | |
import PostLayout from "../components/PostLayout"; | |
import Header from "../components/Header"; | |
import Shell from "../layouts/Shell"; |
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
# Not everything is defined here, just what was mentioned in the article | |
type User { | |
id: ID! | |
name: String! | |
avatar: Image! | |
isPro: Boolean! | |
viewerHasFollowed: Boolean! | |
shots(exclude: ID): ShotConnection! | |
} |
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 datetime | |
import operator | |
from base64 import b64decode as _unbase64 | |
from base64 import b64encode as _base64 | |
from functools import reduce | |
from django.db.models import Q | |
from graphene import relay | |
from graphql_relay.connection import connectiontypes |
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
// src/pages/Homepage.tsx | |
import React from "react"; | |
export default function Homepage() { | |
return <div>Homepage/div>; | |
} |
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
My Awesome Sketch | |
First State | |
some event -> Second State | |
Second State |