Skip to content

Instantly share code, notes, and snippets.

View chrissm79's full-sized avatar

Christopher Moore chrissm79

View GitHub Profile
@chrissm79
chrissm79 / App.tsx
Last active December 29, 2019 03:46
Relay Snapshots
// create relay environment
import { RelaySnapshot } from './RelaySnapshot'
import { RecordSource } from './RecordSource'
import { Store } from './Store'
export const environment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
})

####Current Problem

Let's say we have a collection of users and we just want to eager load the first 5 activities per user. If we use the code below, instead of getting 5 activities per user, we only get 5 activities total.

return App\Models\User::with(['activities' => function ($q) {
    $q->take(5); // We want to load 5 activities per user rather than 5 total
}])->get();
@chrissm79
chrissm79 / relayMutationExample.js
Created November 12, 2015 22:50
Update mutation with Relay that does not update the view upon a successful response
// ./components/Customer.js
import React, {Component} from 'react';
import Relay from 'react-relay';
import UpdateCustomerEmailMutation from '../mutations/UpdateCustomerEmailMutation';
class Customer extends Component {
render() {
console.log(this.props.customer);
const customer = this.props.customer;
return (
@chrissm79
chrissm79 / relaySchema.json
Created November 12, 2015 19:29
Example relay schema
{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"types": [{