// @flow import gql from 'graphql-tag' import {getApi} from './__settings.js'; import {Reglamentos} from './types/reglamentos' import {ReglamentosInput} from './types/reglamentosinput' export const reglamentosApi = { // Queries getAll : function (){ return { select : async (selection:string):Promise> =>{ const {data : {reglamentosGetAll}} = await getApi().query({ query : gql` query reglamentosGetAll{ reglamentosGetAll{ ${selection} } } ` , variables : {}, }); return reglamentosGetAll } } }, getByGrupoId : function (grupoId:string){ return { select : async (selection:string):Promise> =>{ const {data : {reglamentosGetByGrupoId}} = await getApi().query({ query : gql` query reglamentosGetByGrupoId($grupoId: ID!){ reglamentosGetByGrupoId(grupoId: $grupoId){ ${selection} } } ` , variables : {grupoId}, }); return reglamentosGetByGrupoId } } }, getById : function (id:string){ return { select : async (selection:string):Promise =>{ const {data : {reglamentosGetById}} = await getApi().query({ query : gql` query reglamentosGetById($id: ID!){ reglamentosGetById(id: $id){ ${selection} } } ` , variables : {id}, }); return reglamentosGetById } } }, // Mutations deleteItem : function (id:string){ return { select : async (selection:string):Promise => { const {data : {reglamentosDelete}} = getApi().mutate({ mutation: gql` mutation reglamentosDelete($id: ID!){ reglamentosDelete(id: $id){ ${selection} } } ` , variables : {id}, }); return reglamentosDelete } } }, insert : function (input:ReglamentosInput){ return { select : async (selection:string):Promise => { const {data : {reglamentosInsert}} = getApi().mutate({ mutation: gql` mutation reglamentosInsert($input: ReglamentosInput!){ reglamentosInsert(input: $input){ ${selection} } } ` , variables : {input}, }); return reglamentosInsert } } }, update : function (id:string,input:ReglamentosInput?){ return { select : async (selection:string):Promise => { const {data : {reglamentosUpdate}} = getApi().mutate({ mutation: gql` mutation reglamentosUpdate($id: ID!,$input: ReglamentosInput){ reglamentosUpdate(id: $id,input: $input){ ${selection} } } ` , variables : {id,input}, }); return reglamentosUpdate } } }, }