Skip to content

Instantly share code, notes, and snippets.

View AugustoCalaca's full-sized avatar

Augusto Calaca AugustoCalaca

View GitHub Profile
@AugustoCalaca
AugustoCalaca / UserList.spec.tsx
Created November 5, 2019 15:04
Simple test using relay-test-utils and react-testing-library
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { MockPayloadGenerator } from 'relay-test-utils';
import UserListDefault from '../UserList';
import Environment from 'path/to/Environment';
afterEach(cleanup);
describe('<UserList />', () => {
it('should reject query', () => {
@AugustoCalaca
AugustoCalaca / Environment.tsx
Last active March 13, 2020 13:54
New logger event-based relay
import {
Environment,
Network,
RecordSource,
Store,
} from 'relay-runtime';
import { RelayTransactionLogger } from './RelayTransactionLogger';
// Define a function that fetches the results of an operation (query/mutation/etc)
import { useNavigationParam } from 'react-navigation-hooks';
import { graphql, usePreloadedQuery } from 'react-relay/hooks';
const query = graphql`
query TaskDetailQuery($nodeId: ID!) {
task: node(id: $nodeId) {
... on Task {
title
}
}
@AugustoCalaca
AugustoCalaca / brightnessDown.sh
Created December 30, 2019 00:00
brightness lxde debian 10
#!/bin/sh
# create the file brightnessDown.sh and run
# chmod a+x brightnessDown.sh
ACTUAL=$(xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1);
echo "$ACTUAL";
RESULT="$ACTUAL"-0.1;
NEW_VALUE=$(echo "$RESULT" | bc);
RESULT=$(echo "0$NEW_VALUE");
@AugustoCalaca
AugustoCalaca / defer-array.md
Created December 31, 2019 17:05 — forked from robrichard/defer-array.md
Relay Compatible `@defer` & `@stream`

Using @defer under an array field will return multiple patches. Patches are unique combinations of label and path

{
  items {
    id
    ...frag @defer(label: "my-label")
  }
}
@AugustoCalaca
AugustoCalaca / TransactionList.spec.tsx
Last active February 7, 2023 22:27
test using relay hooks, relay-test-utils and react-testing-library
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { MockPayloadGenerator } from 'relay-test-utils';
import { useRelayEnvironment } from 'react-relay/hooks';
import TransactionList from '../TransactionList';
afterEach(cleanup);
describe('<TransactionList />', () => {
it('should reject query', () => {
import React, { Suspense, useCallback, useState } from 'react';
import { graphql, useLazyLoadQuery, usePaginationFragment } from 'react-relay/hooks';
const TransactionsListPagination = (props) => {
const {
data,
loadNext,
isLoadingNext,
hasNext,
refetch,
@AugustoCalaca
AugustoCalaca / useAuth.tsx
Created February 26, 2020 17:34 — forked from sibelius/useAuth.tsx
useAuth hook to handle authentication, use @inline to consume Relay/GraphQL data outside components
import { useEffect } from 'react';
import { graphql, readInlineData } from 'react-relay';
import { useHistory } from '../routing/useHistory';
import { useAuth_user } from './__generated__/useAuth_user.graphql';
const useAuthFragment = graphql`
fragment useAuth_user on User @inline {
id
@AugustoCalaca
AugustoCalaca / useAuth.js
Created March 5, 2020 21:51 — forked from gsasouza/useAuth.js
Relay hook to handle authenticantion
import { ROOT_ID } from 'relay-runtime';
import { useRelayEnvironment } from 'react-relay/hooks';
import { useLocation, useHistory } from 'react-router-dom';
import { commitLocalUpdate } from 'react-relay'
import { useMutation } from 'relay-hooks/lib';
import { AuthUserMutation } from 'mutations/AuthUserMutation';
export const TOKEN_KEY = 'KEY';
@AugustoCalaca
AugustoCalaca / testingLibraryRelay.tsx
Created March 25, 2020 18:37 — forked from sibelius/testingLibraryRelay.tsx
how to properly test relay mutation with testing library
it('should call mutation properly', async () => {
// eslint-disable-next-line
const { debug, getByText, getByTestId } = render(<MyComponent />);
const customMockResolvers = {
...mockResolvers,
};
const name = 'myName';