Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Question: use only GET but avoid send full query and combine GET and POST #27

Open
havran opened this issue Oct 4, 2018 · 1 comment

Comments

@havran
Copy link

havran commented Oct 4, 2018

Hello.

  1. It's possible use only hashed queries, without send full query (even of client side error is triggered)? I want prepare and store all hashed query on server myself, without use 'automatic query resend'.

  2. I use useGETForHashedQueries: true and if persisted query is not stored on server side client try send full query (which is big) through GET (which create error fastcgi request record is too big on NGINX). It's possible configure link to send full query through POST and hashed query through GET?

Thanks.

@havran
Copy link
Author

havran commented Oct 5, 2018

Ok. I found answer to second question (Angular, typescript):

  private getCmsClient() {
    const cache = new InMemoryCache({
      addTypename: true,
      fragmentMatcher: fragmentMatcher,
    });

    const httpLink: HttpLinkHandler = this.httpLink.create({
      uri: 'http://web.local/graphql',
    });

    const queryAsPostMiddleware: ApolloLink = new ApolloLink( (operation: Operation, forward: NextLink) => {
      const context = operation.getContext();
      if (context.http.includeQuery && context.method === 'GET') {
        context.method = 'POST';
        operation.setContext(context);
      }
      return forward(operation);
    });

    const persistedQueryLink: ApolloLink = createPersistedQueryLink({
      useGETForHashedQueries: true,
    });

    this.apollo.create(
      {
        link: from([persistedQueryLink, queryAsPostMiddleware, httpLink]) as any,
        cache: cache,
      },
      'cms',
    );
  }

queryAsPostMiddleware make all queries sent always with POST.

I think answer for first question is simple return null on same middleware instead of return forward(operation), am I right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant