├── .cursorignore ├── .github ├── CODEOWNERS └── workflows │ └── genesis.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── lerna.json ├── package.json ├── packages ├── .watchmanconfig ├── flipper-plugin-react-native-apollo-devtools │ ├── .gitignore │ ├── README.md │ ├── babel.config.js │ ├── flipper-plugin-react-native-apollo-devtools-v1.0.0.tgz │ ├── flipper-plugin-react-native-apollo-devtools-v1.2.0.tgz │ ├── jest-setup.ts │ ├── package.json │ ├── src │ │ ├── Details.tsx │ │ ├── Header.tsx │ │ ├── List.tsx │ │ ├── __tests__ │ │ │ └── test.spec.tsx │ │ ├── index.tsx │ │ ├── typings.ts │ │ └── utils.ts │ └── tsconfig.json └── react-native-apollo-devtools-client │ ├── .editorconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .yarnrc │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── README.md │ ├── babel.config.js │ ├── package.json │ ├── scripts │ └── bootstrap.js │ ├── src │ ├── __tests__ │ │ └── index.test.tsx │ ├── flipperUtils.ts │ ├── index.ts │ ├── initializeFlipperUtils.ts │ └── typings.ts │ ├── tsconfig.build.json │ └── tsconfig.json ├── tsconfig.json └── yarn.lock /.cursorignore: -------------------------------------------------------------------------------- 1 | # Distribution and Environment 2 | dist/* 3 | build/* 4 | venv/* 5 | env/* 6 | *.env 7 | .env.* 8 | virtualenv/* 9 | .python-version 10 | .ruby-version 11 | .node-version 12 | 13 | # Logs and Temporary Files 14 | *.log 15 | *.tsv 16 | *.csv 17 | *.txt 18 | tmp/* 19 | temp/* 20 | .tmp/* 21 | *.temp 22 | *.cache 23 | .cache/* 24 | logs/* 25 | 26 | # Sensitive Data 27 | *.json 28 | *.xml 29 | *.yml 30 | *.yaml 31 | *.properties 32 | properties.json 33 | *.sqlite 34 | *.sqlite3 35 | *.dbsql 36 | secrets.* 37 | *secret* 38 | *password* 39 | *credential* 40 | .npmrc 41 | .yarnrc 42 | .aws/* 43 | .config/* 44 | 45 | # Credentials and Keys 46 | *.pem 47 | *.ppk 48 | *.key 49 | *.pub 50 | *.p12 51 | *.pfx 52 | *.htpasswd 53 | *.keystore 54 | *.jks 55 | *.truststore 56 | *.cer 57 | id_rsa* 58 | known_hosts 59 | authorized_keys 60 | .ssh/* 61 | .gnupg/* 62 | .pgpass 63 | 64 | # Config Files 65 | *.conf 66 | *.toml 67 | *.ini 68 | .env.local 69 | .env.development 70 | .env.test 71 | .env.production 72 | config/* 73 | 74 | # Documentation and Notes 75 | *.md 76 | *.mdx 77 | *.rst 78 | *.txt 79 | docs/* 80 | README* 81 | CHANGELOG* 82 | LICENSE* 83 | CONTRIBUTING* 84 | 85 | # Database Files 86 | *.sql 87 | *.db 88 | *.dmp 89 | *.dump 90 | *.backup 91 | *.restore 92 | *.mdb 93 | *.accdb 94 | *.realm* 95 | 96 | # Backup and Archive Files 97 | *.bak 98 | *.backup 99 | *.swp 100 | *.swo 101 | *.swn 102 | *~ 103 | *.old 104 | *.orig 105 | *.archive 106 | *.gz 107 | *.zip 108 | *.tar 109 | *.rar 110 | *.7z 111 | 112 | # Compiled and Binary Files 113 | *.pyc 114 | *.pyo 115 | **/__pycache__/** 116 | *.class 117 | *.jar 118 | *.war 119 | *.ear 120 | *.dll 121 | *.exe 122 | *.so 123 | *.dylib 124 | *.bin 125 | *.obj 126 | 127 | # IDE and Editor Files 128 | .idea/* 129 | *.iml 130 | .vscode/* 131 | .project 132 | .classpath 133 | .settings/* 134 | *.sublime-* 135 | .atom/* 136 | .eclipse/* 137 | *.code-workspace 138 | .history/* 139 | 140 | # Build and Dependency Directories 141 | node_modules/* 142 | bower_components/* 143 | vendor/* 144 | packages/* 145 | jspm_packages/* 146 | .gradle/* 147 | target/* 148 | out/* 149 | 150 | # Testing and Coverage Files 151 | coverage/* 152 | .coverage 153 | htmlcov/* 154 | .pytest_cache/* 155 | .tox/* 156 | junit.xml 157 | test-results/* 158 | 159 | # Mobile Development 160 | *.apk 161 | *.aab 162 | *.ipa 163 | *.xcarchive 164 | *.provisionprofile 165 | google-services.json 166 | GoogleService-Info.plist 167 | 168 | # Certificate and Security Files 169 | *.crt 170 | *.csr 171 | *.ovpn 172 | *.p7b 173 | *.p7s 174 | *.pfx 175 | *.spc 176 | *.stl 177 | *.pem.crt 178 | ssl/* 179 | 180 | # Container and Infrastructure 181 | *.tfstate 182 | *.tfstate.backup 183 | .terraform/* 184 | .vagrant/* 185 | docker-compose.override.yml 186 | kubernetes/* 187 | 188 | # Design and Media Files (often large and binary) 189 | *.psd 190 | *.ai 191 | *.sketch 192 | *.fig 193 | *.xd 194 | assets/raw/* 195 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @mohit23x -------------------------------------------------------------------------------- /.github/workflows/genesis.yml: -------------------------------------------------------------------------------- 1 | name: Quality Checks 2 | on: 3 | schedule: 4 | - cron: "0 17 * * *" 5 | jobs: 6 | Analysis: 7 | uses: razorpay/genesis/.github/workflows/quality-checks.yml@master 8 | secrets: inherit 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | packages/**/node_modules 3 | packages/.DS_Store 4 | .DS_Store 5 | packages/**/lib 6 | packages/**/example -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Razorpay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 React Native Apollo Devtools 2 | 3 | [](https://www.npmjs.com/package/react-native-apollo-devtools-client) 4 | 5 | 6 | [Flipper](https://github.com/facebook/flipper) plugin to visualise [apollo client](https://github.com/apollographql/apollo-client) cache, queries and mutations for React Native. 7 | 8 | This plugin offers feature parity with the official devtool for React Native since the [official apollo client devtool](https://github.com/apollographql/apollo-client-devtools) only supports web platform and does not supports React Native. 9 | 10 | Read more about it in our blog post [here](https://engineering.razorpay.com/apollo-client-devtools-for-flipper-bc5337b3a411). 11 | 12 | image 13 | 14 | ###### *Devtools in action with the Ricky and Morty GraphQL API based react native [sample app](https://github.com/HarrisonHenri/rick-morty-react-native-shop)* 15 | 16 |
17 | 18 | ## 📱 Setting up mobile app 19 | 20 | 1. Install dependecies 21 | 22 | ``` 23 | yarn add -D react-native-apollo-devtools-client 24 | 25 | yarn add -D react-native-flipper 26 | ``` 27 | 28 | 2. Initialize the plugin with apollo client 29 | 30 | ``` 31 | import { apolloDevToolsInit } from 'react-native-apollo-devtools-client'; 32 | 33 | const client = new ApolloClient({ 34 | // ... 35 | }) 36 | 37 | if(__DEV__){ 38 | apolloDevToolsInit(client); 39 | } 40 | 41 | ``` 42 | 43 | ## 🖥️ Setting up Flipper 44 | 45 | 1. Install [Flipper](https://fbflipper.com/) in your machine, and make sure the emulator/device is recognized by flipper by setting up proper SDK path in flipper settings. 46 | 47 | 2. Go to `plugins manager` -> `install plugin` -> search `react-native-apollo` and install the plugin named `react-native-apollo-devtools` 48 | 49 | 3. Restart Flipper 50 | 51 | 4. Launch the mobile app and you should see `Apollo Devtools` in the list of plugin in disable section, Click `+` icon to enable it 🎉 52 | 53 | 54 | ![Untitled-2022-10-11-1036](https://user-images.githubusercontent.com/36567063/195002113-bdb270c2-d03a-45fd-a112-e350963c082b.png) 55 | 56 | ## ⭐ Stargazers 57 | 58 | [![Stargazers repo roster for @razorpay/react-native-apollo-devtools](https://reporoster.com/stars/razorpay/react-native-apollo-devtools)](https://github.com/razorpay/react-native-apollo-devtools/stargazers) 59 | 60 | ## 📝 License 61 | 62 | Licensed under the [MIT License](./LICENSE.md). 63 | 64 | Link to our [Code of Conduct](https://github.com/razorpay/.github/blob/master/CODE_OF_CONDUCT.md) 65 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*"], 3 | "version": "1.2.0", 4 | "npmClient": "yarn", 5 | "useWorkspaces": true 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-apollo-devtools", 3 | "version": "1.2.0", 4 | "description": "Apollo devtools for React Native", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "private": true, 8 | "workspaces": [ 9 | "packages/*" 10 | ], 11 | "scripts": { 12 | "start": "lerna run --parallel start" 13 | }, 14 | "devDependencies": { 15 | "lerna": "^4.0.0", 16 | "typescript": "^4.5.5" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist/ 3 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/README.md: -------------------------------------------------------------------------------- 1 | The flipper plugin implementation for the [react-native-apollo-devtools](https://github.com/razorpay/react-native-apollo-devtools) 2 | 3 | Read the documentation here: https://github.com/razorpay/react-native-apollo-devtools -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@babel/preset-typescript', 4 | '@babel/preset-react', 5 | ['@babel/preset-env', {targets: {node: 'current'}}] 6 | ], 7 | }; 8 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/flipper-plugin-react-native-apollo-devtools-v1.0.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razorpay/react-native-apollo-devtools/0df97d262adc890ad87cca3df783084b689238c9/packages/flipper-plugin-react-native-apollo-devtools/flipper-plugin-react-native-apollo-devtools-v1.0.0.tgz -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/flipper-plugin-react-native-apollo-devtools-v1.2.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/razorpay/react-native-apollo-devtools/0df97d262adc890ad87cca3df783084b689238c9/packages/flipper-plugin-react-native-apollo-devtools/flipper-plugin-react-native-apollo-devtools-v1.2.0.tgz -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/jest-setup.ts: -------------------------------------------------------------------------------- 1 | // See https://github.com/facebook/flipper/pull/3327 for why we need this 2 | // @ts-ignore 3 | global.electronRequire = require; 4 | require("@testing-library/react"); 5 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://fbflipper.com/schemas/plugin-package/v2.json", 3 | "name": "flipper-plugin-react-native-apollo-devtools", 4 | "id": "react-native-apollo-devtools", 5 | "version": "1.2.0", 6 | "pluginType": "client", 7 | "main": "dist/bundle.js", 8 | "flipperBundlerEntry": "src/index.tsx", 9 | "license": "MIT", 10 | "keywords": [ 11 | "graphql", 12 | "flipper-plugin", 13 | "apollo client", 14 | "devtool", 15 | "react native" 16 | ], 17 | "icon": "rocket", 18 | "title": "Apollo Devtools", 19 | "bugs": { 20 | "email": "mohit.lodha@razorpay.com" 21 | }, 22 | "scripts": { 23 | "lint": "flipper-pkg lint", 24 | "prepack": "flipper-pkg lint && flipper-pkg bundle", 25 | "build": "flipper-pkg bundle", 26 | "watch": "flipper-pkg bundle --watch", 27 | "test": "jest --no-watchman", 28 | "pack": "flipper-pkg pack" 29 | }, 30 | "peerDependencies": { 31 | "@emotion/styled": "*", 32 | "antd": "*", 33 | "flipper-plugin": "*", 34 | "react": "*", 35 | "react-dom": "*" 36 | }, 37 | "devDependencies": { 38 | "@apollo/client": "^3.3.13", 39 | "@babel/preset-react": "latest", 40 | "@babel/preset-typescript": "latest", 41 | "@emotion/styled": "latest", 42 | "@testing-library/react": "latest", 43 | "@types/jest": "latest", 44 | "@types/react": "latest", 45 | "@types/react-dom": "latest", 46 | "antd": "latest", 47 | "flipper-pkg": "latest", 48 | "flipper-plugin": "latest", 49 | "graphql": "latest", 50 | "jest": "latest", 51 | "jest-mock-console": "latest", 52 | "react": "latest", 53 | "react-dom": "latest", 54 | "typescript": "^5.2.2" 55 | }, 56 | "jest": { 57 | "testEnvironment": "jsdom", 58 | "setupFiles": [ 59 | "/jest-setup.ts" 60 | ] 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/Details.tsx: -------------------------------------------------------------------------------- 1 | import React, { Fragment } from "react"; 2 | import { Layout, DataInspector, DetailSidebar } from "flipper-plugin"; 3 | import { Button, Typography, Tooltip } from "antd"; 4 | import { CopyOutlined } from "@ant-design/icons"; 5 | import { BlockType } from "./typings"; 6 | 7 | export function Details({ 8 | selectedItem, 9 | onCopy, 10 | }: { 11 | selectedItem: BlockType; 12 | onCopy: (...args: any) => void; 13 | }) { 14 | return ( 15 | 16 | 17 | 18 | {selectedItem?.operationType} 19 | 20 | {selectedItem?.name} 21 |
22 | 23 | {selectedItem?.blocks?.map((block, index) => { 24 | const key = `block${index}`; 25 | if (block.blockType === "GQLString") { 26 | return ( 27 | 28 | 29 | {block?.blockLabel} 30 | 31 | 32 |
{block?.blockValue?.trim()}
33 |
34 |
35 |
36 | ); 37 | } else if (block.blockType === "Object") { 38 | return ( 39 | 40 | 41 | {block?.blockLabel} 42 | 43 | 45 | 46 | 47 | ); 48 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/List.tsx: -------------------------------------------------------------------------------- 1 | import { Button, Tabs } from "antd"; 2 | import { Layout } from "flipper-plugin"; 3 | import React, { Dispatch, SetStateAction, memo } from "react"; 4 | import { BlockType, Data } from "./typings"; 5 | 6 | export const TabsEnum = { 7 | query: { key: "query", value: "Query", plural: "Queries" }, 8 | mutation: { key: "mutation", value: "Mutation", plural: "Mutations" }, 9 | cache: { key: "cache", value: "Cache", plural: "Caches" }, 10 | }; 11 | 12 | const TabItem = memo( 13 | ({ 14 | active, 15 | onPress, 16 | data, 17 | }: { 18 | active: boolean; 19 | onPress: Dispatch>; 20 | data: any; 21 | }) => { 22 | return ( 23 | 31 | ); 32 | } 33 | ); 34 | 35 | const { TabPane } = Tabs; 36 | 37 | const sortData = (a: BlockType, b: BlockType) => 38 | a.name && b.name && a.name < b.name ? -1 : 1; 39 | 40 | export function List({ 41 | data, 42 | activeTab, 43 | selectedItem, 44 | filter, 45 | onItemSelect, 46 | onTabChange, 47 | }: { 48 | data: Data; 49 | activeTab: string; 50 | selectedItem: BlockType; 51 | filter: string; 52 | onItemSelect: (block: BlockType) => void; 53 | onTabChange: (nextTab: string) => void; 54 | }) { 55 | const filterData = (d: BlockType) => 56 | filter === "" || 57 | d.id?.includes(filter) || 58 | d.name?.toLocaleLowerCase()?.includes(filter); 59 | 60 | return ( 61 | 62 | 63 | {/* CACHE */} 64 | 65 | {data?.cache 66 | ?.filter(filterData) 67 | .sort(sortData) 68 | .map((d, i) => { 69 | const active = 70 | activeTab === TabsEnum.cache.key && 71 | selectedItem?.name === d?.name; 72 | 73 | return ( 74 | 80 | ); 81 | })} 82 | 83 | {/* QUERY */} 84 | 85 | {data?.queries 86 | ?.filter(filterData) 87 | .sort(sortData) 88 | .map((d) => { 89 | const active = 90 | activeTab === TabsEnum.query.key && selectedItem?.id === d?.id; 91 | 92 | return ( 93 | 99 | ); 100 | })} 101 | 102 | {/* MUTATION */} 103 | 104 | {data?.mutations 105 | ?.filter(filterData) 106 | .sort(sortData) 107 | .map((d) => { 108 | const active = 109 | activeTab === TabsEnum.mutation.key && 110 | selectedItem?.id === d?.id; 111 | 112 | return ( 113 | 119 | ); 120 | })} 121 | 122 | 123 | 124 | ); 125 | } 126 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/__tests__/test.spec.tsx: -------------------------------------------------------------------------------- 1 | import {TestUtils} from 'flipper-plugin'; 2 | import * as Plugin from '..'; 3 | 4 | // Read more: https://fbflipper.com/docs/tutorial/js-custom#testing-plugin-logic 5 | // API: https://fbflipper.com/docs/tutorial/js-custom#testing-plugin-logic 6 | test('It can store data', () => { 7 | const {instance, sendEvent} = TestUtils.startPlugin(Plugin); 8 | 9 | expect(instance.data.get()).toEqual({}); 10 | 11 | sendEvent('newData', {id: 'firstID'}); 12 | sendEvent('newData', {id: 'secondID'}); 13 | 14 | expect(instance.data.get()).toMatchInlineSnapshot(` 15 | Object { 16 | "firstID": Object { 17 | "id": "firstID", 18 | }, 19 | "secondID": Object { 20 | "id": "secondID", 21 | }, 22 | } 23 | `); 24 | }); 25 | 26 | // Read more: https://fbflipper.com/docs/tutorial/js-custom#testing-plugin-logic 27 | // API: https://fbflipper.com/docs/tutorial/js-custom#testing-plugin-logic 28 | test('It can render data', async () => { 29 | const {instance, renderer, sendEvent} = TestUtils.renderPlugin(Plugin); 30 | 31 | expect(instance.data.get()).toEqual({}); 32 | 33 | sendEvent('newData', {id: 'firstID'}); 34 | sendEvent('newData', {id: 'secondID'}); 35 | 36 | expect(await renderer.findByTestId('firstID')).not.toBeNull(); 37 | expect(await renderer.findByTestId('secondID')).toMatchInlineSnapshot(` 38 |
41 |       {"id":"secondID"}
42 |     
43 | `); 44 | }); 45 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/index.tsx: -------------------------------------------------------------------------------- 1 | import { Layout, message } from "antd"; 2 | import { PluginClient, createState, usePlugin, useValue } from "flipper-plugin"; 3 | import React, { useState } from "react"; 4 | import { Details } from "./Details"; 5 | import { Header } from "./Header"; 6 | import { List, TabsEnum } from "./List"; 7 | import { BlockType, Data, Events } from "./typings"; 8 | import { 9 | createCacheBlock, 10 | createMutationBlocks, 11 | createQueryBlocks, 12 | } from "./utils"; 13 | 14 | const { Content } = Layout; 15 | const InitialData = { 16 | id: "x", 17 | lastUpdateAt: new Date(), 18 | queries: [], 19 | mutations: [], 20 | cache: [], 21 | }; 22 | 23 | let timer: NodeJS.Timeout; 24 | 25 | function debounce(func: (...args: any) => any, timeout = 7000): void { 26 | clearTimeout(timer); 27 | timer = setTimeout(() => { 28 | // @ts-expect-error add typings for this 29 | func.apply(this); 30 | }, timeout); 31 | } 32 | 33 | export function plugin(client: PluginClient) { 34 | const data = createState(InitialData, { persist: "data" }); 35 | const selectedItem = createState({}); 36 | 37 | const resyncData = () => { 38 | debounce(() => { 39 | // @ts-expect-error string is not assignable to never 40 | client.send("GQL:request", {}); 41 | }); 42 | }; 43 | 44 | const resetSync = () => { 45 | clearTimeout(timer); 46 | }; 47 | 48 | client.onMessage("GQL:response", (newData) => { 49 | const finalData = { 50 | ...newData, 51 | mutations: createMutationBlocks(newData?.mutations).reverse(), 52 | queries: createQueryBlocks(newData?.queries).reverse(), 53 | cache: createCacheBlock(newData?.cache), 54 | }; 55 | 56 | data.set(finalData as Data); 57 | // @ts-expect-error 58 | client.send("GQL:ack", {}); 59 | resyncData(); 60 | }); 61 | 62 | client.addMenuEntry({ 63 | label: "*️⃣ clear", 64 | handler: async () => { 65 | data.set(InitialData); 66 | clearSelectedItem(); 67 | }, 68 | }); 69 | 70 | client.addMenuEntry({ 71 | label: "🔄 refresh", 72 | handler: async () => { 73 | // @ts-expect-error string is not assignable to never 74 | client.send("GQL:request", {}); 75 | }, 76 | }); 77 | 78 | client.onDestroy(() => { 79 | resetSync(); 80 | }); 81 | 82 | client.onDisconnect(() => { 83 | resetSync(); 84 | }); 85 | 86 | function onCopyText(text: string) { 87 | client.writeTextToClipboard(text); 88 | message.success("Copied successfully 🎉"); 89 | } 90 | 91 | function handleSelectedItem(block: BlockType) { 92 | selectedItem.set(block); 93 | } 94 | 95 | function clearSelectedItem() { 96 | selectedItem.set({}); 97 | } 98 | 99 | return { 100 | data, 101 | onCopyText, 102 | selectedItem, 103 | handleSelectedItem, 104 | clearSelectedItem, 105 | }; 106 | } 107 | 108 | export function Component() { 109 | const [filter, setFilter] = useState(""); 110 | const instance = usePlugin(plugin); 111 | const data = useValue(instance.data); 112 | const selectedItem = useValue(instance.selectedItem); 113 | const [activeTab, setActiveTab] = useState(TabsEnum.cache.key); 114 | 115 | function handleTabChange(nextTab: string) { 116 | setActiveTab(nextTab); 117 | instance.clearSelectedItem(); 118 | setFilter(""); 119 | } 120 | 121 | return ( 122 | 123 |
124 | 132 |
133 | 134 | ); 135 | } 136 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/typings.ts: -------------------------------------------------------------------------------- 1 | 2 | import type { 3 | ArrayOfMutations, 4 | ArrayOfQuery, 5 | } from 'react-native-apollo-devtools-client/src/typings'; 6 | 7 | 8 | export type TabItemType = { id: string, name: string|null } 9 | 10 | export type RawMutationBody = { 11 | id: string; 12 | name:string|null, 13 | body: string, 14 | variables: object 15 | } 16 | 17 | export type RawQueryBody = { 18 | id: string; 19 | name:string|null, 20 | cachedData: object, 21 | 22 | 23 | } 24 | 25 | export type RawData = { 26 | id: string; 27 | lastUpdateAt: Date; 28 | queries: ArrayOfQuery; 29 | mutations: ArrayOfMutations; 30 | cache: Array; 31 | } 32 | 33 | export type Data = { 34 | id: string; 35 | lastUpdateAt: Date; 36 | queries: Array; 37 | mutations: Array; 38 | cache: Array; 39 | }; 40 | 41 | export type Events = { 42 | "GQL:response": RawData; 43 | "GQL:request": Data; 44 | "GQL:ack": boolean; 45 | }; 46 | 47 | export type BlockType = { 48 | id?: string, 49 | operationType?: string, 50 | name?:string | null, 51 | blocks?: Array<{ 52 | blockType: string; 53 | blockLabel: string; 54 | blockValue: any; 55 | }> 56 | } 57 | -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { BlockType } from './typings' 2 | import { ArrayOfMutations, ArrayOfQuery } from "react-native-apollo-devtools-client/src/typings"; 3 | 4 | 5 | function createQueryBlocks(queries: ArrayOfQuery) { 6 | return queries.map((query) => { 7 | return { 8 | id: query?.id, 9 | name: query?.name, 10 | operationType: "Query", 11 | blocks: [ 12 | // { 13 | // blockType: "GQLString", 14 | // blockLabel: "Query String", 15 | // blockValue: query.queryString, 16 | // }, 17 | { 18 | blockType: "Object", 19 | blockLabel: "Query Variables", 20 | blockValue: query?.variables, 21 | }, 22 | { 23 | blockType: "Object", 24 | blockLabel: "Cached Query Data", 25 | blockValue: query?.cachedData, 26 | }, 27 | ], 28 | }; 29 | }); 30 | } 31 | 32 | function createCacheBlock(cacheObject: object) { 33 | return [...Object.keys(cacheObject || {})].map((c) => { 34 | // @ts-expect-error 35 | const cache = cacheObject[c]; 36 | 37 | return { 38 | id: cache?.id || cache.__typename, 39 | name: c, 40 | operationType: "Cache", 41 | blocks: [ 42 | { 43 | blockType: "Object", 44 | blockLabel: "Cached Data", 45 | blockValue: cache, 46 | }, 47 | ], 48 | }; 49 | }); 50 | } 51 | 52 | function createMutationBlocks(mutations: ArrayOfMutations): BlockType[] { 53 | return mutations.map((mutation) => { 54 | // TODO: cached response (options not applicable in apollo 3.5+) 55 | return { 56 | id: mutation?.id, 57 | name: mutation.name, 58 | operationType: "Mutation", 59 | blocks: [ 60 | { 61 | blockType: "GQLString", 62 | blockLabel: "Mutation Query String", 63 | blockValue: mutation.body, 64 | }, 65 | { 66 | blockType: "Object", 67 | blockLabel: "Query Variables", 68 | blockValue: mutation.variables, 69 | }, 70 | ], 71 | }; 72 | }); 73 | } 74 | 75 | 76 | export { createCacheBlock, createMutationBlocks, createQueryBlocks } -------------------------------------------------------------------------------- /packages/flipper-plugin-react-native-apollo-devtools/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2017", 4 | "module": "ES6", 5 | "jsx": "react", 6 | "sourceMap": true, 7 | "noEmit": true, 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "esModuleInterop": true, 11 | "forceConsistentCasingInFileNames": true 12 | }, 13 | "files": ["src/index.tsx"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # node.js 48 | # 49 | node_modules/ 50 | npm-debug.log 51 | yarn-debug.log 52 | yarn-error.log 53 | 54 | # BUCK 55 | buck-out/ 56 | \.buckd/ 57 | android/app/libs 58 | android/keystores/debug.keystore 59 | 60 | # Expo 61 | .expo/* 62 | 63 | # generated by bob 64 | lib/ 65 | example/ -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | To run the example app on Android: 24 | 25 | ```sh 26 | yarn example android 27 | ``` 28 | 29 | To run the example app on iOS: 30 | 31 | ```sh 32 | yarn example ios 33 | ``` 34 | 35 | To run the example app on Web: 36 | 37 | ```sh 38 | yarn example web 39 | ``` 40 | 41 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 42 | 43 | ```sh 44 | yarn typescript 45 | yarn lint 46 | ``` 47 | 48 | To fix formatting errors, run the following: 49 | 50 | ```sh 51 | yarn lint --fix 52 | ``` 53 | 54 | Remember to add tests for your change if possible. Run the unit tests by: 55 | 56 | ```sh 57 | yarn test 58 | ``` 59 | 60 | ### Commit message convention 61 | 62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 63 | 64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 65 | - `feat`: new features, e.g. add new method to the module. 66 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 67 | - `docs`: changes into documentation, e.g. add usage example for the module.. 68 | - `test`: adding or updating tests, e.g. add integration tests using detox. 69 | - `chore`: tooling changes, e.g. change CI config. 70 | 71 | Our pre-commit hooks verify that your commit message matches this format when committing. 72 | 73 | ### Linting and tests 74 | 75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 76 | 77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 78 | 79 | Our pre-commit hooks verify that the linter and tests pass when committing. 80 | 81 | ### Publishing to npm 82 | 83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 84 | 85 | To publish new versions, run the following: 86 | 87 | ```sh 88 | yarn release 89 | ``` 90 | 91 | ### Scripts 92 | 93 | The `package.json` file contains various scripts for common tasks: 94 | 95 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 96 | - `yarn typescript`: type-check files with TypeScript. 97 | - `yarn lint`: lint files with ESLint. 98 | - `yarn test`: run unit tests with Jest. 99 | - `yarn example start`: start the Metro server for the example app. 100 | - `yarn example android`: run the example app on Android. 101 | - `yarn example ios`: run the example app on iOS. 102 | 103 | ### Sending a pull request 104 | 105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 106 | 107 | When you're sending a pull request: 108 | 109 | - Prefer small pull requests focused on one change. 110 | - Verify that linters and tests are passing. 111 | - Review the documentation to make sure it looks good. 112 | - Follow the pull request template when opening a pull request. 113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 114 | 115 | ## Code of Conduct 116 | 117 | ### Our Pledge 118 | 119 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 120 | 121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 122 | 123 | ### Our Standards 124 | 125 | Examples of behavior that contributes to a positive environment for our community include: 126 | 127 | - Demonstrating empathy and kindness toward other people 128 | - Being respectful of differing opinions, viewpoints, and experiences 129 | - Giving and gracefully accepting constructive feedback 130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 131 | - Focusing on what is best not just for us as individuals, but for the overall community 132 | 133 | Examples of unacceptable behavior include: 134 | 135 | - The use of sexualized language or imagery, and sexual attention or 136 | advances of any kind 137 | - Trolling, insulting or derogatory comments, and personal or political attacks 138 | - Public or private harassment 139 | - Publishing others' private information, such as a physical or email 140 | address, without their explicit permission 141 | - Other conduct which could reasonably be considered inappropriate in a 142 | professional setting 143 | 144 | ### Enforcement Responsibilities 145 | 146 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 147 | 148 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 149 | 150 | ### Scope 151 | 152 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 153 | 154 | ### Enforcement 155 | 156 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 157 | 158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 159 | 160 | ### Enforcement Guidelines 161 | 162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 163 | 164 | #### 1. Correction 165 | 166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 167 | 168 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 169 | 170 | #### 2. Warning 171 | 172 | **Community Impact**: A violation through a single incident or series of actions. 173 | 174 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 175 | 176 | #### 3. Temporary Ban 177 | 178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 179 | 180 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 181 | 182 | #### 4. Permanent Ban 183 | 184 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 185 | 186 | **Consequence**: A permanent ban from any sort of public interaction within the community. 187 | 188 | ### Attribution 189 | 190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 192 | 193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 194 | 195 | [homepage]: https://www.contributor-covenant.org 196 | 197 | For answers to common questions about this code of conduct, see the FAQ at 198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 199 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 mohit23x 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/README.md: -------------------------------------------------------------------------------- 1 | The flipper client-plugin implementation for the [react-native-apollo-devtools](https://github.com/razorpay/react-native-apollo-devtools) 2 | 3 | Read the documentation here: https://github.com/razorpay/react-native-apollo-devtools 4 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-apollo-devtools-client", 3 | "version": "1.2.0", 4 | "description": "Apollo devtools for React Native", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "react-native-apollo-devtools-client.podspec", 17 | "!lib/typescript/example", 18 | "!android/build", 19 | "!ios/build", 20 | "!**/__tests__", 21 | "!**/__fixtures__", 22 | "!**/__mocks__" 23 | ], 24 | "scripts": { 25 | "test": "jest", 26 | "typescript": "tsc --noEmit", 27 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 28 | "prepare": "bob build", 29 | "release": "release-it", 30 | "example": "yarn --cwd example", 31 | "pods": "cd example && pod-install --quiet", 32 | "bootstrap": "yarn example && yarn && yarn pods" 33 | }, 34 | "keywords": [ 35 | "react-native", 36 | "ios", 37 | "android" 38 | ], 39 | "author": "mohit23x (https://github.com/mohit23x)", 40 | "license": "MIT", 41 | "publishConfig": { 42 | "registry": "https://registry.npmjs.org/" 43 | }, 44 | "devDependencies": { 45 | "@apollo/client": "^3.4.17", 46 | "@commitlint/config-conventional": "^11.0.0", 47 | "@react-native-community/eslint-config": "^2.0.0", 48 | "@release-it/conventional-changelog": "^2.0.0", 49 | "@types/jest": "^26.0.0", 50 | "@types/react": "^16.9.19", 51 | "@types/react-native": "0.62.13", 52 | "commitlint": "^11.0.0", 53 | "eslint": "^7.2.0", 54 | "eslint-config-prettier": "^7.0.0", 55 | "eslint-plugin-prettier": "^3.1.3", 56 | "husky": "^6.0.0", 57 | "jest": "^26.0.1", 58 | "pod-install": "^0.1.0", 59 | "prettier": "^2.0.5", 60 | "react-native-builder-bob": "^0.18.0", 61 | "react-native-flipper": "^0.131.1", 62 | "release-it": "^14.2.2", 63 | "typescript": "^5.2.2" 64 | }, 65 | "peerDependencies": { 66 | "react": "*", 67 | "react-native": "*" 68 | }, 69 | "jest": { 70 | "preset": "react-native", 71 | "modulePathIgnorePatterns": [ 72 | "/example/node_modules", 73 | "/lib/" 74 | ] 75 | }, 76 | "commitlint": { 77 | "extends": [ 78 | "@commitlint/config-conventional" 79 | ] 80 | }, 81 | "release-it": { 82 | "git": { 83 | "commitMessage": "chore: release ${version}", 84 | "tagName": "v${version}" 85 | }, 86 | "npm": { 87 | "publish": true 88 | }, 89 | "github": { 90 | "release": true 91 | }, 92 | "plugins": { 93 | "@release-it/conventional-changelog": { 94 | "preset": "angular" 95 | } 96 | } 97 | }, 98 | "eslintConfig": { 99 | "root": true, 100 | "extends": [ 101 | "@react-native-community", 102 | "prettier" 103 | ], 104 | "rules": { 105 | "prettier/prettier": [ 106 | "error", 107 | { 108 | "quoteProps": "consistent", 109 | "singleQuote": true, 110 | "tabWidth": 2, 111 | "trailingComma": "es5", 112 | "useTabs": false 113 | } 114 | ] 115 | } 116 | }, 117 | "eslintIgnore": [ 118 | "node_modules/", 119 | "lib/" 120 | ], 121 | "prettier": { 122 | "quoteProps": "consistent", 123 | "singleQuote": true, 124 | "tabWidth": 2, 125 | "trailingComma": "es5", 126 | "useTabs": false 127 | }, 128 | "react-native-builder-bob": { 129 | "source": "src", 130 | "output": "lib", 131 | "targets": [ 132 | "commonjs", 133 | "module", 134 | [ 135 | "typescript", 136 | { 137 | "project": "tsconfig.build.json" 138 | } 139 | ] 140 | ] 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/src/flipperUtils.ts: -------------------------------------------------------------------------------- 1 | import { print } from 'graphql'; 2 | import type { ArrayOfQuery, RawQueryData } from './typings'; 3 | 4 | export function getQueries(queryMap: Map): ArrayOfQuery { 5 | let queries: ArrayOfQuery = []; 6 | 7 | if (queryMap) { 8 | [...queryMap.values()].forEach( 9 | ({ document, variables, observableQuery, diff, lastDiff }, queryId) => { 10 | if (document && observableQuery) { 11 | queries.push({ 12 | queryString: print(document), 13 | variables, 14 | cachedData: diff?.result || lastDiff?.diff?.result, 15 | name: observableQuery?.queryName, 16 | id: queryId?.toString(), 17 | }); 18 | } 19 | } 20 | ); 21 | } 22 | return queries; 23 | } 24 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/src/index.ts: -------------------------------------------------------------------------------- 1 | import { addPlugin } from 'react-native-flipper'; 2 | import { initializeFlipperUtils } from './initializeFlipperUtils'; 3 | import type { ApolloClientType, Callback } from './typings'; 4 | 5 | export const apolloDevToolsInit = ( 6 | client: ApolloClientType, 7 | config?: { 8 | onConnect?: Callback; 9 | onDisconnect?: Callback; 10 | } 11 | ): void => 12 | addPlugin({ 13 | getId() { 14 | return 'react-native-apollo-devtools'; 15 | }, 16 | onConnect(connection) { 17 | initializeFlipperUtils(connection, client); 18 | if (config?.onConnect) config?.onConnect(); 19 | }, 20 | onDisconnect() { 21 | if (config?.onDisconnect) config?.onDisconnect(); 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/src/initializeFlipperUtils.ts: -------------------------------------------------------------------------------- 1 | import type { DocumentNode } from '@apollo/client'; 2 | import { getOperationName } from '@apollo/client/utilities'; 3 | import type { Flipper } from 'react-native-flipper'; 4 | import { getQueries } from './flipperUtils'; 5 | import type { 6 | ApolloClientState, 7 | ApolloClientType, 8 | ArrayOfMutations, 9 | ArrayOfQuery, 10 | MutationData, 11 | } from './typings'; 12 | 13 | let tick = 0; 14 | 15 | function getTime(): string { 16 | const date = new Date(); 17 | return `${date.getHours()}:${date.getMinutes()}`; 18 | } 19 | 20 | function extractQueries(client: ApolloClientType): Map { 21 | // @ts-expect-error queryManager is private method 22 | if (!client || !client.queryManager) { 23 | return new Map(); 24 | } 25 | // @ts-expect-error queryManager is private method 26 | return client.queryManager.queries; 27 | } 28 | 29 | function getAllQueries(client: ApolloClientType): ArrayOfQuery { 30 | const queryMap = extractQueries(client); 31 | const allQueries = getQueries(queryMap); 32 | return allQueries; 33 | } 34 | 35 | type MutationObject = { 36 | mutation: DocumentNode; 37 | variables: object; 38 | loading: boolean; 39 | error: object; 40 | }; 41 | function getMutationData( 42 | allMutations: Record 43 | ): Array { 44 | return [...Object.keys(allMutations)]?.map((key) => { 45 | const { mutation, variables, loading, error } = allMutations[key]; 46 | 47 | return { 48 | id: key, 49 | name: getOperationName(mutation), 50 | variables, 51 | loading, 52 | error, 53 | body: mutation?.loc?.source?.body, 54 | }; 55 | }); 56 | } 57 | 58 | function getAllMutations(client: ApolloClientType): ArrayOfMutations { 59 | // @ts-expect-error private method 60 | const allMutations = client.queryManager.mutationStore || {}; 61 | 62 | const final = getMutationData(allMutations); 63 | 64 | return final; 65 | } 66 | 67 | function getCurrentState(client: ApolloClientType): Promise { 68 | tick++; 69 | 70 | let currentState: ApolloClientState; 71 | 72 | return new Promise((res) => { 73 | setTimeout(() => { 74 | currentState = { 75 | id: tick, 76 | lastUpdateAt: getTime(), 77 | queries: getAllQueries(client), 78 | mutations: getAllMutations(client), 79 | cache: client.cache.extract(true), 80 | }; 81 | res(currentState); 82 | }, 0); 83 | }).then(() => { 84 | return currentState; 85 | }); 86 | } 87 | 88 | function debounce(func: (...args: any) => any, timeout = 500): () => any { 89 | let timer: NodeJS.Timeout; 90 | return (...args) => { 91 | clearTimeout(timer); 92 | timer = setTimeout(() => { 93 | // @ts-expect-error add typings for this 94 | func.apply(this, args); 95 | }, timeout); 96 | }; 97 | } 98 | 99 | export const initializeFlipperUtils = async ( 100 | flipperConnection: Flipper.FlipperConnection, 101 | apolloClient: ApolloClientType 102 | ): Promise => { 103 | let acknowledged = true; 104 | let apolloData: null | ApolloClientState = await getCurrentState( 105 | apolloClient 106 | ); 107 | 108 | function sendData(): void { 109 | if (apolloData) { 110 | flipperConnection.send('GQL:response', apolloData); 111 | acknowledged = false; 112 | apolloData = null; 113 | } 114 | } 115 | 116 | const logger = async (): Promise => { 117 | if (acknowledged) { 118 | apolloData = await getCurrentState(apolloClient); 119 | sendData(); 120 | } 121 | }; 122 | 123 | flipperConnection.receive('GQL:ack', () => { 124 | acknowledged = true; 125 | sendData(); 126 | }); 127 | 128 | flipperConnection.receive('GQL:request', async () => { 129 | flipperConnection.send('GQL:response', await getCurrentState(apolloClient)); 130 | }); 131 | 132 | apolloClient.__actionHookForDevTools(debounce(() => logger())); 133 | 134 | flipperConnection.send('GQL:response', apolloData); 135 | }; 136 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/src/typings.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | ApolloClient, 3 | NormalizedCacheObject, 4 | ObservableQuery, 5 | } from '@apollo/client'; 6 | import type { QueryInfo } from '@apollo/client/core/QueryInfo'; 7 | import type { ASTNode } from 'graphql'; 8 | 9 | export type ApolloClientType = ApolloClient; 10 | 11 | export type Variables = QueryInfo['variables']; 12 | 13 | export type RawQueryData = { 14 | document: ASTNode; 15 | variables: Variables; 16 | observableQuery: ObservableQuery; 17 | lastDiff: any; 18 | diff: any; 19 | queryId: string; 20 | }; 21 | 22 | export type QueryData = { 23 | id: string; 24 | queryString: string; 25 | variables: Variables; 26 | cachedData: string; 27 | name: string | undefined; 28 | }; 29 | 30 | export type MutationData = { 31 | id: string; 32 | name: string | null; 33 | variables: object; 34 | loading: boolean; 35 | error: object; 36 | body: string | undefined; 37 | }; 38 | 39 | export type Callback = () => any; 40 | 41 | export type ArrayOfQuery = Array; 42 | export type ArrayOfMutations = Array; 43 | 44 | export type ApolloClientState = { 45 | id: number; 46 | lastUpdateAt: string; 47 | queries: ArrayOfQuery; 48 | mutations: ArrayOfMutations; 49 | cache: object; 50 | }; 51 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/react-native-apollo-devtools-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "react-native-apollo-devtools-client": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "resolveJsonModule": true, 22 | "skipLibCheck": true, 23 | "strict": true, 24 | "target": "esnext" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./packages" 4 | } 5 | } 6 | --------------------------------------------------------------------------------