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

Error linke not working #516

Closed
serendipity1004 opened this issue Dec 30, 2019 · 9 comments
Closed

Error linke not working #516

serendipity1004 opened this issue Dec 30, 2019 · 9 comments
Labels
help wanted Extra attention is needed investigate We are looking into the issue link Relates to link functionality

Comments

@serendipity1004
Copy link
Collaborator

I am using below code to concat error link to auth link and http link. However, the prints in the ErrorLink do not show when I purposefully cause error. I might be using it wrong because it's not documented. Any suggestions what might be wrong?

final HttpLink httpLink = HttpLink(
  uri: CONFIG.domain + '/apollo_api',
);

final CustomAuthLink authLink = CustomAuthLink(getHeaders: () async {
  final String token = await Storage.getAuthToken();
  final packageInfo = await PackageInfo.fromPlatform();

  final String buildNo = packageInfo.buildNumber;
  String os;

  if (Platform.isIOS) {
    os = 'iOS';
  } else if (Platform.isAndroid) {
    os = 'android';
  }

  return {
    'authorization': token,
    'os': os,
    'buildNo': buildNo,
  };
});

final ErrorLink errorLink = ErrorLink(
  errorHandler: (ErrorResponse response) {
    print(response);
    if (response.exception is OperationException) {
      print('exception:${response.exception}');
    }
  },
);

final Link link = authLink.concat(httpLink).concat(errorLink);

client = GraphQLClient(
  link: link,
  cache: NormalizedInMemoryCache(
    dataIdFromObject: cacheKeyBuilder,
  ),
);
@bsr203
Copy link

bsr203 commented Dec 30, 2019

can you try authLink.concat(errorLink.concat(httpLink)) . At least this is how I do it

@serendipity1004
Copy link
Collaborator Author

@bsr203 unfortunately it does not work. What version of graphql-flutter are you using? I am currently using graphql_flutter: ^2.1.1-beta.4

@bsr203
Copy link

bsr203 commented Dec 30, 2019

graphql_flutter: ^2.1.1-beta.5

@mainawycliffe
Copy link
Collaborator

What about final Link link = authLink..concat(httpLink)..concat(errorLink);?

And is it working when you concat just two Links? You can also try the Link.from function and see if it works.

@mainawycliffe mainawycliffe added help wanted Extra attention is needed investigate We are looking into the issue labels Dec 31, 2019
@klavs klavs added the link Relates to link functionality label Feb 16, 2020
@ekoto4
Copy link

ekoto4 commented Apr 30, 2020

@serendipity1004 @mainawycliffe
Did anyone find a fix to this? I am also running into this problem. It seems that no matter the order, the linking stops working correctly when the http link is concatenated. Anything concatenated afterwards does not work. Thank you for the help in advance!

@Bat-m
Copy link

Bat-m commented Oct 1, 2020

same problem for me, any news or idea ?

@ekoto4
Copy link

ekoto4 commented Oct 1, 2020

same problem for me, any news or idea ?

The order the links are concatenated matters. This ow i set it up to get a token that was passed in the header.

static final Link _link = _tokenLink.concat(_authLink.concat(_httpLink));

I think you can substitute tokenLink for errorLink and it should work.

@Bat-m
Copy link

Bat-m commented Oct 2, 2020

ok thx for your answer but I try with this

and it works

@micimize
Copy link
Collaborator

micimize commented Oct 7, 2020

This is outdated / likely solved by using gql_links in 4.0.0-beta.1 #648. Please open a new issue if not

@micimize micimize closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed investigate We are looking into the issue link Relates to link functionality
Projects
None yet
Development

No branches or pull requests

7 participants