This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial typescript examples update to emulate real to life project * convert to use render callback styled Query * fix parameterized type * use named import not relative * trying to get build running with package resolution from live repo * wip through examples build * Fix missing type annotations * More type fixes * comment out test and update App setup for 2.0 * runtime test cannot be compiled because we now have types guarding input. * changelog
- Loading branch information
Showing
22 changed files
with
464 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 98 additions & 62 deletions
160
examples/typescript/src/schema.json → examples/typescript/schema.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,4 @@ | ||
// @flow | ||
import * as React from 'react'; | ||
import { graphql } from 'react-apollo'; | ||
import gql from 'graphql-tag'; | ||
import Character from './Character'; | ||
|
||
// import types generated by codegen | ||
import { GetCharacterQuery, GetCharacterQueryVariables } from './schema'; | ||
|
||
export const HERO_QUERY = gql` | ||
query GetCharacter($episode: Episode!) { | ||
hero(episode: $episode) { | ||
name | ||
id | ||
friends { | ||
name | ||
id | ||
appearsIn | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const CharacterWithoutData = ({ loading, hero, error }) => { | ||
if (loading) return <div>Loading</div>; | ||
if (error) return <h1>ERROR</h1>; | ||
return ( | ||
<div> | ||
{hero && ( | ||
<div> | ||
<h3>{hero.name}</h3> | ||
{hero.friends && | ||
hero.friends.map( | ||
friend => | ||
friend && ( | ||
<h6 key={friend.id}> | ||
{friend.name}:{' '} | ||
{friend.appearsIn.map(x => x && x.toLowerCase()).join(', ')} | ||
</h6> | ||
), | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export const Character = graphql< | ||
{}, | ||
GetCharacterQuery, | ||
GetCharacterQueryVariables | ||
>(HERO_QUERY, { | ||
options: ({ episode }) => ({ | ||
variables: { episode }, | ||
}), | ||
props: ({ data }) => ({ ...data }), | ||
})(CharacterWithoutData); | ||
|
||
export const App = () => ( | ||
<div> | ||
<Character episode="NEWHOPE" /> | ||
</div> | ||
); | ||
export const App = () => <Character episode="NEWHOPE" />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
query GetCharacter($episode: Episode!) { | ||
hero(episode: $episode) { | ||
name | ||
id | ||
friends { | ||
name | ||
id | ||
appearsIn | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react'; | ||
import { | ||
GetCharacter, | ||
GetCharacter_hero_friends, | ||
} from './__generated__/GetCharacter'; | ||
import { Query, QueryResult } from 'react-apollo'; | ||
// import Query, { QueryResult } from '../../../src/Query'; | ||
|
||
const QUERY = require('./Character.graphql'); | ||
// https://github.com/Microsoft/TypeScript/issues/6395#issuecomment-282133254 | ||
class CharacterQuery extends Query<GetCharacter> {} | ||
|
||
export interface CharacterProps { | ||
episode: string; | ||
} | ||
|
||
export const Character = (props: CharacterProps) => { | ||
const { episode } = props; | ||
return ( | ||
<CharacterQuery query={QUERY} variables={{ episode }}> | ||
{({ loading, data, error }: QueryResult<GetCharacter>) => { | ||
if (loading) return <div>Loading</div>; | ||
if (error) return <h1>ERROR</h1>; | ||
const { hero } = data; | ||
return ( | ||
<div> | ||
{hero && ( | ||
<div> | ||
<h3>{hero.name}</h3> | ||
{hero.friends && | ||
hero.friends.map( | ||
(friend: GetCharacter_hero_friends) => | ||
friend && ( | ||
<h6 key={friend.id}> | ||
{friend.name}:{' '} | ||
{friend.appearsIn | ||
.map(x => x && x.toLowerCase()) | ||
.join(', ')} | ||
</h6> | ||
), | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}} | ||
</CharacterQuery> | ||
); | ||
}; | ||
|
||
export default Character; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.