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

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 {
@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 {
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;
mutation($dossierId: ID!, $instructeurId: ID!, $body: String!, $attachment: ID) {
dossierEnvoyerMessage(input: {
dossierId: $dossierId,
instructeurId: $instructeurId,
body: $body,
attachment: $attachment
}) {
message {
body
}
@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> {
@tchak
tchak / json-schema.ts
Last active August 31, 2019 15:00
Orbit JSONSchema
import { Schema } from '@orbit/data';
import { JSONAPISerializer } from '@orbit/jsonapi';
import { Dict } from '@orbit/utils';
export interface JSONSchemaType {
type: 'object' | 'string' | 'number' | 'boolean';
pattern?: string;
}
export interface JSONSchemaRef {
@tchak
tchak / hints-with-meta-2.js
Last active July 3, 2019 17:29
Orbit hints with meta
class MyMemorySource extends MemorySource {
async _query(query, hints) {
if (hints && hints.data) {
let identities = hints.data.primaryData ? hints.data.primaryData : hints.data;
let data;
if (Array.isArray(identities)) {
data = this._cache.query(q => q.findRecords(identities));
} else {
data = this._cache.query(q => q.findRecord(identities));
}
@tchak
tchak / orbit-jsonapi-client.md
Last active June 24, 2019 17:29
Orbit jsonapi Client

Is it possible to use Orbit.js as a simple fetching client with a json:api server? The answer is yes, with certain caveats. First one is you still need to write a schema.

import { Schema } from '@orbit/data';
import JSONAPISource from '@orbit/jsonapi’;

const schema = new Schema({
  models: {
    article: {
      attributes: {
@tchak
tchak / action-cable-source.ts
Last active May 30, 2019 21:47
Orbit ActionCableSource
import Orbit, {
Source,
SourceSettings,
RecordOperation,
buildTransform
} from '@orbit/data';
import {
JSONAPISerializer,
JSONAPISerializerSettings,
ResourceOperationsDocument