Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Add a basic example app bundled with Rollup. #2839

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/rollup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.min.js
*.min.js.map
9 changes: 9 additions & 0 deletions examples/rollup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="root"></div>
<script src="app-with-react.min.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions examples/rollup/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { Query, ApolloProvider } from 'react-apollo';
import gql from 'graphql-tag';

const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: 'http://localhost:4000/graphql',
})
});

client.writeData({
data: {
isLoggedIn: false
}
});

const IS_LOGGED_IN = gql`
query IsUserLoggedIn {
isLoggedIn @client
}
`;

function toggle() {
const result = client.readQuery({ query: IS_LOGGED_IN });
client.writeData({
data: {
isLoggedIn: !result.isLoggedIn
}
});
}

ReactDOM.render(
<ApolloProvider client={client}>
<Query query={IS_LOGGED_IN}>
{({data}) => [
"logged " + (data.isLoggedIn ? "in" : "out"),
<br/>,
<button onClick={toggle}>
log {data.isLoggedIn ? "out" : "in"}
</button>,
]}
</Query>
</ApolloProvider>,
document.getElementById('root'),
);
Loading