Skip to content

Instantly share code, notes, and snippets.

Avatar
GH drop ICE

Paul Chavard tchak

GH drop ICE
View GitHub Profile
View export-pj-demarche.gql
query exportDemarche($demarcheNumber: Int!, $after: String) {
demarche(number: $demarcheNumber) {
number
dossiers(first: 100, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
...DossierFragment
View revisions.rb
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
View pagination-graphql.md

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 Jul 30, 2020
Query avec PieceJustificativeChamp
View query.gql
query getDossier($dossierNumber: Int!) {
dossier(number: $dossierNumber) {
id
number
champs {
id
label
stringValue
... on PieceJustificativeChamp {
file {
View TrackedLiveQuery.ts
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[];
View read-only-array.ts
export interface IReadonlyArray<T> extends Iterable<T> {
/**
*
*/
readonly length: number;
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
View action-cable-source.ts
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;
View envoyer-message.gql
mutation($dossierId: ID!, $instructeurId: ID!, $body: String!, $attachment: ID) {
dossierEnvoyerMessage(input: {
dossierId: $dossierId,
instructeurId: $instructeurId,
body: $body,
attachment: $attachment
}) {
message {
body
}
@tchak
tchak / introspection.gql
Last active Nov 20, 2019
GraphQL IntrospectionQuery
View introspection.gql
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
types {
...FullType
@tchak
tchak / store.ts
Last active Oct 20, 2019
Orbit Store Interface
View store.ts
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> {