Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make redirect from network layer? #95

Closed
CostaRico opened this issue Oct 9, 2017 · 10 comments
Closed

How to make redirect from network layer? #95

CostaRico opened this issue Oct 9, 2017 · 10 comments

Comments

@CostaRico
Copy link

Here is my network layer:

function fetchQuery(operation,
                    variables,
                    cacheConfig,
                    uploadables) {
	// return fetch('https://api.graph.cool/relay/v1/cj07pfjjj1nbq0148rutjhxd5', {
	return fetch('http://localhost:3010/graphql', {
		method: 'POST',
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json',
		},
		body: JSON.stringify({query: operation.text})
	}).then(response => {
		
		if(response.status == 401){
			throw new Error('Network response was not ok.');
// HOW TO MAKE REDIRECT TO LOGIN PAGE HERE?

		}
		

		return response.json();
	});
}

Help me please!

@taion
Copy link
Member

taion commented Oct 9, 2017

You wouldn't do the redirect from the network layer. Instead add a route that e.g. throws a RedirectException in render, per https://github.com/4Catalyzer/found-relay/blob/2071b36c445475c367d6ecaf18cce1dfefafab46/test/modern/render.test.js#L144-L150

@taion taion closed this as completed Oct 9, 2017
@CostaRico
Copy link
Author

CostaRico commented Oct 9, 2017

@taion I've tried this way, but resolving is undefined always.
props are filled if there are no error
errors are undefined all the time

If error:
2017-10-09_22-37-40

if data exist:
2017-10-09_22-48-09

May be something wrong with my network layer?

import fetch from 'isomorphic-fetch';
import {
  Environment,
  Network,
  RecordSource,
  Store
} from 'relay-runtime';

function fetchQuery(
  operation,
  variables,
  cacheConfig,
  uploadables
) {
  return fetch('https://api.graph.cool/relay/v1/cj07pfjjj1nbq0148rutjhxd5', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({query: operation.text})
  }).then(response => {
    return response.json();
  }).then(data=>{
    debugger;
    return data;
  });
}

// Create a network layer from the fetch function
const network = Network.create(fetchQuery);
const source = new RecordSource();
const store = new Store(source);

export default new Environment({
  network,
  store
})

You can try it:
https://github.com/CostaRico/graphql-relay

yarn install
yarn fetch-schema
yarn relay
yarn dev

@taion
Copy link
Member

taion commented Oct 9, 2017

Your lockfile has alpha 6. Upgrade to the latest alpha.

@CostaRico
Copy link
Author

CostaRico commented Oct 9, 2017

@taion if I switch to "found-relay": "latest", then I get error like here #76
"Cannot read property 'Container' of undefined"

So if I get it right way, I need to switch to "react-relay": ">=0.6.0 <1.0.0", also.
Is it mean I cant use relay modern in this case?

Thx u for your time!

@taion
Copy link
Member

taion commented Oct 9, 2017

Not latest. Use next.

@peet86
Copy link

peet86 commented Oct 23, 2017

@taion: My question is really similar to the original one... I would like to handle the error case when the graphql server is down.. I can catch the error in the network layer but I want to handle it somewhere in the rendering logic. But as I see non of the render method's arguments reflect the http error state..

I've tried to check for props === null but sometimes props has null value even when the graphql endpoint is up.. and as I see there is no other relevant/reliable argument to check...

GraphQL down:
{ error: null, props: null, retry: null, resolving: true }

GraphQL up:
{ error: null, props: object or null, <-- ??? retry: [func], resolving: true }

@CostaRico: have you solved this at the end?

@CostaRico
Copy link
Author

@peet86 I solved what I've asked originally thx to @taion
But next I've tried to render error messages and it's too difficult.
Finally i've chosen to use redux for a while.
When relay modern will be more mature I try again. :)

@taion
Copy link
Member

taion commented Oct 23, 2017

@peet86 See facebook/relay#1913. I'm just matching the semantics of <QueryRenderer> here. You'll want to explicitly throw in the network layer.

@CostaRico
Copy link
Author

@taion it would be nice to have some examples
and thx u for all u do!

@taion
Copy link
Member

taion commented Oct 24, 2017

It would be better for such examples to live upstream for facebook/relay. They're not specific to Found Relay.

taion added a commit that referenced this issue Jun 13, 2019
67233b8 Merge branch 'found-modern' into found-modern-universal
4680f9a chore: Update dependencies
8c6d421 chore(deps): Bump webpack from 4.33.0 to 4.34.0
6818eea chore(deps): Bump css-loader from 2.1.1 to 3.0.0 (#180)
b8b6ddd chore(deps): Bump husky from 2.4.0 to 2.4.1
5c97a91 chore(deps): Bump webpack-cli from 3.3.3 to 3.3.4
d194df1 chore(deps): Bump webpack-dev-server from 3.7.0 to 3.7.1
e54c18f chore(deps): Bump webpack-cli from 3.3.2 to 3.3.3
fda3954 chore(deps): Bump prettier from 1.17.1 to 1.18.0
5cf714a chore(deps): Bump webpack-dev-server from 3.6.0 to 3.7.0
886cb88 chore(deps): Bump lint-staged from 8.1.7 to 8.2.0
e71290a chore(deps): Bump husky from 2.3.0 to 2.4.0
b99f4e4 chore(deps): Bump webpack-dev-server from 3.5.1 to 3.6.0
448ea0c chore(deps): Bump webpack from 4.32.2 to 4.33.0
10d58fc chore(deps): Bump webpack-dev-server from 3.4.1 to 3.5.1
cf4ae71 chore(deps): Bump eslint-plugin-import from 2.17.2 to 2.17.3
b043e71 chore(deps): Bump graphql from 14.3.0 to 14.3.1
0a4feb4 chore(deps): Bump webpack from 4.32.1 to 4.32.2
851a44f chore(deps): Bump @babel/node from 7.2.2 to 7.4.5
9a511b5 chore(deps): Bump @babel/core from 7.4.4 to 7.4.5
4a71ce7 chore(deps): Bump @babel/runtime from 7.4.4 to 7.4.5
704a7b8 chore(deps): Bump webpack from 4.32.0 to 4.32.1
299a2de chore(deps): Bump webpack from 4.31.0 to 4.32.0
dc701dc chore(deps): Bump webpack-dev-server from 3.3.1 to 3.4.1
3a2b83c chore(deps): Bump eslint-config-prettier from 4.2.0 to 4.3.0
c072ed3 chore(deps): Bump husky from 2.2.0 to 2.3.0
6794d05 chore(deps): Bump lint-staged from 8.1.6 to 8.1.7
14c437f chore(deps): Bump prettier from 1.17.0 to 1.17.1
b9accb2 chore(deps): Bump babel-loader from 8.0.5 to 8.0.6
11496ef chore(deps): Bump eslint-plugin-prettier from 3.0.1 to 3.1.0
1d00998 chore(deps): Bump webpack from 4.30.0 to 4.31.0
2395d2f chore(deps): Bump graphql from 14.2.1 to 14.3.0
a671556 chore(deps): Bump @4c/babel-preset from 5.1.0 to 5.2.0
ba96398 chore(deps): Bump webpack-cli from 3.3.1 to 3.3.2
b072635 chore(deps): Bump lint-staged from 8.1.5 to 8.1.6
19ed611 chore(deps): Bump eslint-plugin-react from 7.12.4 to 7.13.0
cb3fb66 chore(deps): Bump husky from 2.1.0 to 2.2.0
5bce96c Merge branch 'found-modern' into found-modern-universal
2f4159e chore: Update dependencies
dfad3f2 chore: Update dependencies
5f7ef84 Merge branch 'found-modern' into found-modern-universal
9b2873a chore: Update dependencies
4694d6d chore(deps): Bump @babel/core from 7.4.3 to 7.4.4
8f6c8a0 chore(deps): Bump @babel/cli from 7.4.3 to 7.4.4
0e9665d chore(deps): Bump @babel/runtime from 7.4.3 to 7.4.4
93fd923 chore(deps): Bump eslint-config-prettier from 4.1.0 to 4.2.0
fe56023 chore(deps): Bump husky from 1.3.1 to 2.1.0 (#107)
530a4fa chore(deps): Bump copy-webpack-plugin from 5.0.2 to 5.0.3
aa79c81 chore(deps): Bump webpack-cli from 3.3.0 to 3.3.1
ddaeccd chore(deps): Bump eslint-plugin-import from 2.17.1 to 2.17.2
896e793 chore(deps): Bump express-graphql from 0.7.1 to 0.8.0 (#95)
00a672e Merge branch 'found-modern' into found-modern-universal
4760b5f chore(deps): Bump prettier from 1.16.4 to 1.17.0
8484e70 chore(deps): Bump webpack from 4.29.6 to 4.30.0
2414312 chore(deps): Bump eslint-plugin-import from 2.16.0 to 2.17.1
9f5d506 Merge branch 'found-modern' into found-modern-universal
f56f1f2 chore: Update dependencies
b77d01a chore(deps): Bump webpack-dev-server from 3.3.0 to 3.3.1
3b182e1 chore(deps): Bump webpack-dev-server from 3.2.1 to 3.3.0
59d442b chore(deps): Bump found-relay from 0.4.0-alpha.6 to 0.4.0-alpha.7
d1f0067 chore(deps): Bump found from 0.4.0-alpha.10 to 0.4.0-alpha.12
c29643d chore: Update dependencies
711dae3 Merge branch 'found-modern' into found-modern-universal
0ec6cdb chore(deps): Bump @babel/cli from 7.2.3 to 7.4.3 (#82)
d6d3a79 chore(deps): Bump @babel/core from 7.4.0 to 7.4.3 (#83)
685f43b chore(deps): Bump @babel/runtime from 7.4.2 to 7.4.3 (#81)
d4a110b chore(deps): Bump graphql from 14.2.0 to 14.2.1 (#76)
745fb15 chore(deps): Bump eslint from 5.15.3 to 5.16.0 (#75)
c15ae62 chore(deps): Bump react from 16.8.5 to 16.8.6 (#72)
ccda86a chore(deps): Bump react-dom from 16.8.5 to 16.8.6 (#71)
566fe20 Merge branch 'found-modern' into found-modern-universal
3ee9d3a chore(deps): Bump graphql from 14.1.1 to 14.2.0 (#66)
bd1d909 chore(deps): Bump @4c/babel-preset from 5.0.4 to 5.1.0 (#65)
90681e9 Merge branch 'found-modern' into found-modern-universal
e3d9e38 chore(deps): Bump react from 16.8.4 to 16.8.5 (#62)
7d41e5d chore(deps): Bump copy-webpack-plugin from 5.0.1 to 5.0.2 (#60)
487cdb7 chore(deps): Bump found from 0.4.0-alpha.9 to 0.4.0-alpha.10 (#61)
93c4a1b chore(deps): Bump react-dom from 16.8.4 to 16.8.5 (#63)
dbbf110 Bump regenerator-runtime from 0.12.1 to 0.13.2 (#51)
a651c6d Merge branch 'found-modern' into found-modern-universal
b229831 chore: Add CI (#55)
49680a3 Bump @babel/runtime from 7.4.0 to 7.4.2 (#49)
e64d03e Bump found from 0.4.0-alpha.8 to 0.4.0-alpha.9 (#48)
2425e35 Bump farce from 0.2.7 to 0.2.8 (#47)
6e9d145 Bump found-relay from 0.4.0-alpha.5 to 0.4.0-alpha.6 (#46)
d2dc59c Bump farce from 0.2.7 to 0.2.8
20751d6 Merge branch 'found-modern' into found-modern-universal
5c9d69a chore: Fix import
358aa13 Merge branch 'master' into found-modern-universal
ae03d2f chore: Update dependencies

git-subtree-dir: examples/todomvc-universal
git-subtree-split: 67233b8a55e8c4beeeae3c69396440334c6a3a20
taion added a commit that referenced this issue Jun 13, 2019
67233b8 Merge branch 'found-modern' into found-modern-universal
4680f9a chore: Update dependencies
8c6d421 chore(deps): Bump webpack from 4.33.0 to 4.34.0
6818eea chore(deps): Bump css-loader from 2.1.1 to 3.0.0 (#180)
b8b6ddd chore(deps): Bump husky from 2.4.0 to 2.4.1
5c97a91 chore(deps): Bump webpack-cli from 3.3.3 to 3.3.4
d194df1 chore(deps): Bump webpack-dev-server from 3.7.0 to 3.7.1
e54c18f chore(deps): Bump webpack-cli from 3.3.2 to 3.3.3
fda3954 chore(deps): Bump prettier from 1.17.1 to 1.18.0
5cf714a chore(deps): Bump webpack-dev-server from 3.6.0 to 3.7.0
886cb88 chore(deps): Bump lint-staged from 8.1.7 to 8.2.0
e71290a chore(deps): Bump husky from 2.3.0 to 2.4.0
b99f4e4 chore(deps): Bump webpack-dev-server from 3.5.1 to 3.6.0
448ea0c chore(deps): Bump webpack from 4.32.2 to 4.33.0
10d58fc chore(deps): Bump webpack-dev-server from 3.4.1 to 3.5.1
cf4ae71 chore(deps): Bump eslint-plugin-import from 2.17.2 to 2.17.3
b043e71 chore(deps): Bump graphql from 14.3.0 to 14.3.1
0a4feb4 chore(deps): Bump webpack from 4.32.1 to 4.32.2
851a44f chore(deps): Bump @babel/node from 7.2.2 to 7.4.5
9a511b5 chore(deps): Bump @babel/core from 7.4.4 to 7.4.5
4a71ce7 chore(deps): Bump @babel/runtime from 7.4.4 to 7.4.5
704a7b8 chore(deps): Bump webpack from 4.32.0 to 4.32.1
299a2de chore(deps): Bump webpack from 4.31.0 to 4.32.0
dc701dc chore(deps): Bump webpack-dev-server from 3.3.1 to 3.4.1
3a2b83c chore(deps): Bump eslint-config-prettier from 4.2.0 to 4.3.0
c072ed3 chore(deps): Bump husky from 2.2.0 to 2.3.0
6794d05 chore(deps): Bump lint-staged from 8.1.6 to 8.1.7
14c437f chore(deps): Bump prettier from 1.17.0 to 1.17.1
b9accb2 chore(deps): Bump babel-loader from 8.0.5 to 8.0.6
11496ef chore(deps): Bump eslint-plugin-prettier from 3.0.1 to 3.1.0
1d00998 chore(deps): Bump webpack from 4.30.0 to 4.31.0
2395d2f chore(deps): Bump graphql from 14.2.1 to 14.3.0
a671556 chore(deps): Bump @4c/babel-preset from 5.1.0 to 5.2.0
ba96398 chore(deps): Bump webpack-cli from 3.3.1 to 3.3.2
b072635 chore(deps): Bump lint-staged from 8.1.5 to 8.1.6
19ed611 chore(deps): Bump eslint-plugin-react from 7.12.4 to 7.13.0
cb3fb66 chore(deps): Bump husky from 2.1.0 to 2.2.0
5bce96c Merge branch 'found-modern' into found-modern-universal
2f4159e chore: Update dependencies
dfad3f2 chore: Update dependencies
5f7ef84 Merge branch 'found-modern' into found-modern-universal
9b2873a chore: Update dependencies
4694d6d chore(deps): Bump @babel/core from 7.4.3 to 7.4.4
8f6c8a0 chore(deps): Bump @babel/cli from 7.4.3 to 7.4.4
0e9665d chore(deps): Bump @babel/runtime from 7.4.3 to 7.4.4
93fd923 chore(deps): Bump eslint-config-prettier from 4.1.0 to 4.2.0
fe56023 chore(deps): Bump husky from 1.3.1 to 2.1.0 (#107)
530a4fa chore(deps): Bump copy-webpack-plugin from 5.0.2 to 5.0.3
aa79c81 chore(deps): Bump webpack-cli from 3.3.0 to 3.3.1
ddaeccd chore(deps): Bump eslint-plugin-import from 2.17.1 to 2.17.2
896e793 chore(deps): Bump express-graphql from 0.7.1 to 0.8.0 (#95)
00a672e Merge branch 'found-modern' into found-modern-universal
4760b5f chore(deps): Bump prettier from 1.16.4 to 1.17.0
8484e70 chore(deps): Bump webpack from 4.29.6 to 4.30.0
2414312 chore(deps): Bump eslint-plugin-import from 2.16.0 to 2.17.1
9f5d506 Merge branch 'found-modern' into found-modern-universal
f56f1f2 chore: Update dependencies
b77d01a chore(deps): Bump webpack-dev-server from 3.3.0 to 3.3.1
3b182e1 chore(deps): Bump webpack-dev-server from 3.2.1 to 3.3.0
59d442b chore(deps): Bump found-relay from 0.4.0-alpha.6 to 0.4.0-alpha.7
d1f0067 chore(deps): Bump found from 0.4.0-alpha.10 to 0.4.0-alpha.12
c29643d chore: Update dependencies
711dae3 Merge branch 'found-modern' into found-modern-universal
0ec6cdb chore(deps): Bump @babel/cli from 7.2.3 to 7.4.3 (#82)
d6d3a79 chore(deps): Bump @babel/core from 7.4.0 to 7.4.3 (#83)
685f43b chore(deps): Bump @babel/runtime from 7.4.2 to 7.4.3 (#81)
d4a110b chore(deps): Bump graphql from 14.2.0 to 14.2.1 (#76)
745fb15 chore(deps): Bump eslint from 5.15.3 to 5.16.0 (#75)
c15ae62 chore(deps): Bump react from 16.8.5 to 16.8.6 (#72)
ccda86a chore(deps): Bump react-dom from 16.8.5 to 16.8.6 (#71)
566fe20 Merge branch 'found-modern' into found-modern-universal
3ee9d3a chore(deps): Bump graphql from 14.1.1 to 14.2.0 (#66)
bd1d909 chore(deps): Bump @4c/babel-preset from 5.0.4 to 5.1.0 (#65)
90681e9 Merge branch 'found-modern' into found-modern-universal
e3d9e38 chore(deps): Bump react from 16.8.4 to 16.8.5 (#62)
7d41e5d chore(deps): Bump copy-webpack-plugin from 5.0.1 to 5.0.2 (#60)
487cdb7 chore(deps): Bump found from 0.4.0-alpha.9 to 0.4.0-alpha.10 (#61)
93c4a1b chore(deps): Bump react-dom from 16.8.4 to 16.8.5 (#63)
dbbf110 Bump regenerator-runtime from 0.12.1 to 0.13.2 (#51)
a651c6d Merge branch 'found-modern' into found-modern-universal
b229831 chore: Add CI (#55)
49680a3 Bump @babel/runtime from 7.4.0 to 7.4.2 (#49)
e64d03e Bump found from 0.4.0-alpha.8 to 0.4.0-alpha.9 (#48)
2425e35 Bump farce from 0.2.7 to 0.2.8 (#47)
6e9d145 Bump found-relay from 0.4.0-alpha.5 to 0.4.0-alpha.6 (#46)
d2dc59c Bump farce from 0.2.7 to 0.2.8
20751d6 Merge branch 'found-modern' into found-modern-universal
5c9d69a chore: Fix import
358aa13 Merge branch 'master' into found-modern-universal
ae03d2f chore: Update dependencies

git-subtree-dir: examples/todomvc-universal
git-subtree-split: 67233b8a55e8c4beeeae3c69396440334c6a3a20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants