Skip to content

Instantly share code, notes, and snippets.

View tchak's full-sized avatar
GH drop ICE

Paul Chavard tchak

GH drop ICE
View GitHub Profile
@tchak
tchak / store.ts
Last active October 20, 2019 17:32
Orbit Store Interface
import { QueryResultData } from '@orbit/record-cache';
import { FilterQBParam, SortQBParam, PageQBParam, QueryOrExpression, TransformOrOperations } from '@orbit/data';
export interface Identifier {
type?: string;
id?: string;
lid?: string;
}
export interface LiveArray<Model> extends Iterable<Model> {
mutation($dossierId: ID!, $instructeurId: ID!, $body: String!, $attachment: ID) {
dossierEnvoyerMessage(input: {
dossierId: $dossierId,
instructeurId: $instructeurId,
body: $body,
attachment: $attachment
}) {
message {
body
}
import { RecordIdentity } from '@orbit/data';
import { SyncLiveQuery } from '@orbit/record-cache';
import { consume, dirty } from './tracked';
import { ReadonlyArray } from './readonly-array';
export class LiveQueryArray<M extends RecordIdentity> extends ReadonlyArray<M> {
private readonly _liveQuery: SyncLiveQuery;
private get _content(): M[] {
return this._liveQuery.query() as M[];
import { Source, SourceSettings, buildTransform } from '@orbit/data';
import {
createConsumer,
Cable,
ChannelNameWithParams
} from '@rails/actioncable';
import { JSONAPISerializer, ResourceOperationsDocument } from '@orbit/jsonapi';
export interface ActionCableSourceSettings extends SourceSettings {
cable?: Cable;
@tchak
tchak / query.gql
Created July 30, 2020 09:40
Query avec PieceJustificativeChamp
query getDossier($dossierNumber: Int!) {
dossier(number: $dossierNumber) {
id
number
champs {
id
label
stringValue
... on PieceJustificativeChamp {
file {

Pagination GraphQL

La pagination sur l'API GraphQL se fait par "curseur". Ça veut dire que pour récupérer la prochaine page il faut passer à l'API le "curseur" de la fin de la page précédente.

Voici un exemple. On commence par faire une query pour récupérer les 100 premiers dossiers.

query {
  demarche(number: 123) {
    dossiers(first: 100) {
      pageInfo {
class Survey < ApplicationRecord
has_many :revisions
belongs_to :draft_revision
belongs_to :published_revision
has_many :draft_fields, through: :draft_revision
has_many :fields, through: :published_revision
def publish
self.published_revision = draft_revision
query exportDemarche($demarcheNumber: Int!, $after: String) {
demarche(number: $demarcheNumber) {
number
dossiers(first: 100, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
...DossierFragment
@tchak
tchak / ClientOnly.tsx
Created May 5, 2021 20:32
ClientOnly
// global hydrating so future components don't do this dance, they just render
let hydrating = true;
// Component that renders `null` on the server and the initial browser render
// (while it's "hydrating")
function ClientOnly({ children }) {
// set initial state to whatever the global hydrating is, so once the app is
// hydrated, these components just render, no dance
let [hydrated, setHydrated] = useState(() => !hydrating);
@tchak
tchak / with-body.ts
Last active May 12, 2021 18:40
Remix withBody
import type { ActionFunction, Request } from 'remix';
import { BaseSchema, ValidationError } from 'yup';
type NextActionFunction<Body> = (body: Body) => ReturnType<ActionFunction>;
export async function withBody(
request: Request,
config: (router: ActionRouter) => void
) {
const router = new ActionRouter();