Switch from gql-sketch to react-apollo
See original GitHub issueTackling more ambitious graphql usecases requires standardizing on a client.
import React from 'react';
import { render, Text, View } from 'react-sketchapp';
import { ApolloClient, ApolloProvider, createNetworkInterface, gql, graphql } from 'react-apollo';
import type { User } from './types';
import { fonts, spacing } from './designSystem';
import Profile from './components/Profile';
import Space from './components/Space';
global.setTimeout = (fn, time) => {
NSThread.sleepForTimeInterval(time / 1000);
fn();
}
const UserList = ({ users }) =>
<View style={{ flexDirection: 'row', flexWrap: 'wrap', width: users.length * 300 }}>
{users.map(user => (
<Space key={user.screen_name} h={spacing} v={spacing}>
<Profile user={user} />
</Space>
))}
</View>
const Page = ({ data }) => (
<View>
<Text style={fonts['Title 1']}>Profile Cards w/ GraphQL</Text>
{ data.allProfiles && <UserList users={data.allProfiles} /> }
</View>
);
const ProfilesQuery = gql`query allProfiles {
allProfiles {
screenname,
name,
description,
location,
url,
profileImageUrl,
}
}`;
const PageWithData = graphql(ProfilesQuery, {
options: {
fetchPolicy: 'network-only',
},
})(Page);
const client = new ApolloClient({
networkInterface: createNetworkInterface({
uri: 'https://api.graph.cool/simple/v1/cj09zm1k4jcpc0115ecsoc1k4',
}),
});
export default (context) => {
render(
<ApolloProvider client={client}>
<PageWithData />
</ApolloProvider>
, context.document.currentPage())
}
Unfortunately, this doesn’t work — we only render once, and we can’t force react-apollo to render synchronously.
A way around this could be to have separate entry points for Sketch & non-Sketch to components -
/* baseComponent.js */
const Component = ({ data }) =>
<div>{ data.message }</div>
export const query = `query message { }`;
export default Component;
/* Component.js */
import { graphql, gql } from 'react-apollo';
import Component, { query } from './baseComponent';
const query = gql`${query}`;
export default graphql(query)(Component)
/* Component.sketch.js */
import Component, { query } from './baseComponent';
export const query = query;
export default Component
/* index.js */
import Component from './Component';
render(<ApolloProvider client={client}><Component></ApolloProvider>, $('#root'));
/* index.sketch.js */
import Component, { query } from './Component';
import Client from 'gql-sketch';
Client(endpoint).query(query).then(data =>
<Component data={data} />
)
just typing this this seems like a mess so mayyybe not 🗡
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
GraphQL On The Front-End (React And Apollo)
In this article, we're going to learn how to handle real-time updates on the client-side using GraphQL. We'll be learning how to do...
Read more >Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
This article walks you through migrating your application to Apollo Client 3.0 from previous versions of Apollo Client. To illustrate the migration process, ......
Read more >apollo react: proper way to switch a query's params
For completeness here's my VIDEO_SEARCH_QUERY : export const VIDEO_SEARCH_QUERY = gql` query searchVideos($query: String) { searchVideos(query: ...
Read more >React Hooks support · Issue #2539 · apollographql/react-apollo
I'd like to start a discussion about the possible next-gen API based on react hooks for react-apollo. I think this API brings a...
Read more >Using Apollo Client with a REST API | by November Five
For the actual basic setup of the Apollo Client in your React ... Now that we have 2 queries in users.gql , we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How about:
Basically, doing a server side rendering.
@jongold @mathieudutour I’m working on this now 👍 I can’t get my local plugin to not break whenever I import something though 👎
Will keep you posted!