Giter Site home page Giter Site logo

Comments (12)

benbender avatar benbender commented on June 3, 2024 1

I'm not sure if that's the best approach, but it's what works for me atm - so here is my current solution...

I first had a look at the processRequest()-method to see if there is some way to hook into it's result.headers directly. But as it turns out, headers is simply initiated as an empty array. So no hook there... What I did instead is to add a response-object with an empty "headers"-array to my context, which can be accessed inside my resolvers. This context is available in the result of the actual processRequest()-call and can be used to initialize the former empty headers-array. Be aware that those headers could be overwritten later in the flow and if this might be a problem, it would need to be handled...

So my (simplified) code looks something like the following:

const respond = async (request: Request): Promise<Response> => {
  // ...
  // Extract the GraphQL parameters from the request
  const parameters = getGraphQLParameters(request);
  const result = await processRequest({
    ...parameters,
    request,
    schema,
    contextFactory: () => {
      return {
        request,
        response: {
          headers: {},
        },
        // ...
      };
    },
  });

  if (result.type === "RESPONSE") {
    const headers: Headers = result.context?.response.headers || {};

    for (const { name, value } of result.headers) {
      headers[name] = value;
    }

    return {
      headers,
      body: result.payload,
      status: result.status,
    };
  }
  // ...
};

from graphql-helix.

ibilux avatar ibilux commented on June 3, 2024 1

Thank you @benbender , I have been thinking about doing this. I just needed another opinion on doing this.
Thank you for the confirmation.

from graphql-helix.

ibilux avatar ibilux commented on June 3, 2024 1

@AndreasHald I'm using version 1.7.0 it's working fine (it was released 2 months ago).
PS: latest version is 1.8.0, but it should work fine.

from graphql-helix.

AndreasHald avatar AndreasHald commented on June 3, 2024

@ibilux do you have graphql-helix working with svelte-kit? I can get it working in [email protected] but the latest 1.8 throws an error when starting svelte-kit
Failed to resolve entry for package "graphql-helix". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "graphql-helix" package

from graphql-helix.

benbender avatar benbender commented on June 3, 2024

@AndreasHald Simply use https://github.com/PabloSzx/graphql-ez/tree/main/examples/sveltekit - which integrates SvelteKit, Graphql-Helix & Envelop.

from graphql-helix.

AndreasHald avatar AndreasHald commented on June 3, 2024

@benbender seems interesting, but for now I'd like to try and get something working without a framework and build it from scratch. Do you happen to know the issue I'm having?

from graphql-helix.

benbender avatar benbender commented on June 3, 2024

@AndreasHald yes and no. The bundling process in sveltekit and vite is somewhat brittle atm. They are still figuring out how to handle all edge- and legacy-cases in their esm-packages-only-strategy. This leads to all sorts of problems with various packages in between and is changing between versions. So yes, I've encountered this (broad) class of problems, but not exactly your specific case (as I'm using graphql-ez, as said).

from graphql-helix.

ibilux avatar ibilux commented on June 3, 2024

@AndreasHald Yes, graphql-helix is working with svelte-kit for me.
You can use this as reference, or use it as and svelte-add :
https://github.com/svelte-add/graphql-server

from graphql-helix.

ibilux avatar ibilux commented on June 3, 2024

@benbender did you try using Websockets with svelte-kit ?
Websockets is not supported yet :
https://github.com/PabloSzx/graphql-ez/blob/d5398248d9972d7d304c5ef87db898ecfbb5a5b4/packages/sveltekit/main/src/index.ts#L200

from graphql-helix.

AndreasHald avatar AndreasHald commented on June 3, 2024

@ibilux Ah I see, that reference is using 1.2.3 however, do you have it working using the latest version of graphql-helix?

from graphql-helix.

PabloSzx avatar PabloSzx commented on June 3, 2024

@benbender did you try using Websockets with svelte-kit ?
Websockets is not supported yet :
https://github.com/PabloSzx/graphql-ez/blob/d5398248d9972d7d304c5ef87db898ecfbb5a5b4/packages/sveltekit/main/src/index.ts#L200

Check sveltejs/kit#1563 and sveltejs/kit#2212, those are the reason PUSH and MULTIPART_RESPONSE are not supported

from graphql-helix.

ibilux avatar ibilux commented on June 3, 2024

@PabloSzx Yes, PUSH and MUTLIPART_RESPONSE are not supported yet in svelte-kit, hence, it can't be implemented to Graphql-Helix or graphql-ez. However, you can use this workaround trick : sveltejs/kit#2051

from graphql-helix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.