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

Docs are outdated #409

Open
ighormartins opened this issue Jan 25, 2023 · 4 comments
Open

Docs are outdated #409

ighormartins opened this issue Jan 25, 2023 · 4 comments

Comments

@ighormartins
Copy link

Hi there.

I've been looking at your repo for a while. Love GenQL but like the direction you're taking even more.
However I noticed you've made some changes and added some features but the docs are not update.

Could you please update the docs? Having a website is not necessary if it's too much trouble, just keep it in the README if it's easier.

I'd love to have the docs update so I can start contributing .

@meabed
Copy link
Owner

meabed commented Jan 25, 2023

Thanks @ighormartins yes absolutely, I'm using this is multiple production applications works really well and up to date.

I need to put in more the docs / readme and some examples too, I would add this in the next few days.

Meanwhile if you have any specific question feel free to ask, also you could look at demo apps it have multiple real use cases tested and shows how to use it.

Also please feel free to updated any docs or content that you think it's missing and I will incorporate it

@ighormartins
Copy link
Author

There are 3 main things bothering me right now (in order of how easy -> hard it'd be to contribute to the lib):

  • I'd love to have access to the axios fetcher instance. In my specific case I want to apply an interceptor: https://github.com/bernawil/axios-concurrency, to manage the max amount of concurrent requests.
  • Lack of support for alias. Whenever we want to query the same operation with different variables we have to make two queries.
  • How hard it is to use the lib with apollo-client.

@meabed
Copy link
Owner

meabed commented Jan 26, 2023

  • The fetcher instance could be access like
export const gqLtsClient = createClient({
  url: 'http://localhost:3000/graphql',
});
// example of interceptor 
gqLtsClient?.fetcherInstance?.interceptors.request.use(
  (config) => {
    if (!config.headers || !config.headers['content-type']) {
      config.headers = {
        ...config.headers,
        'content-type': 'application/json',
      };
    }
    return config;
  },
);
  • For sure the Alias support is in progress, the pending work is some typescript typing...
  • You could always use custom fetcher for example apollo-client, but you need to handle file upload, for example I use this with I am testing in nodejs with supertest, example below:
import supertest from 'supertest';
import { extractFiles } from '@gqlts/runtime/dist/extract-files/extract-files';

const app = express();

export const request = supertest(expressApp);

export const supertestGQLClient = createClient({
  fetcherInstance: request,
  fetcherMethod: async (operation, config) => {
    const r = request.post('/graphql');
    const { clone, files } = extractFiles(operation);

    if (files.size > 0) {
      // 1. First document is graphql query with variables
      r.field('operations', JSON.stringify(clone));
      // 2. Second document maps files to variable locations
      const map: any = {};
      let i = 0;
      files.forEach((paths) => {
        map[i++] = paths;
      });
      r.field('map', JSON.stringify(map));
      // 3. all files not (same index as in map)
      let j = 0;
      for (const [file] of files) {
        r.attach(`${j++}`, file, { filename: file.name });
      }
    }

    const { headers = {} } = config || {};
    r.set('Content-Type', 'application/json').set('Accept', 'application/json');
    for (const [key, value] of Object.entries(headers)) {
      r.set(key, String(value));
    }
    if (files.size) {
      r.type('form');
    } else {
      r.send(JSON.stringify(operation));
    }
    return r
      .expect(200)
      .then((response) => {
        return response.body;
      })
      .catch((e) => {
        return { errors: [{ message: e.message, path: ['client'] }] };
      });
  },
});

@ighormartins
Copy link
Author

ighormartins commented Feb 1, 2023

Thank you!
I'll starting moving one of my products from GenQL to GQLTS.

Do you think the alias is possible to solve? From what I'm thinking, the types is going to be very hard.

I didn't even know you were supporting file upload :)

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

2 participants