Giter VIP home page Giter VIP logo

graphql-deduplicator's People

Contributors

am-zigzag avatar chencozocaru avatar gajus avatar katt avatar manishoo avatar notiv-nt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphql-deduplicator's Issues

Not deflating array of strings correctly

Schema

   example: [String]

Before

        "example": [
            "SETUP",
            "MOBILE"
        ],

Deflated

        "example": [
            {
                "0": "S",
                "1": "E",
                "2": "T",
                "3": "U",
                "4": "P"
            },
            {
                "0": "M",
                "1": "O",
                "2": "B",
                "3": "I",
                "4": "L",
                "5": "E"
            }

Could you please release the bugfix from #26?

Hi @gajus. Firstly, thanks - this is a great package that we've been using for a while! Recently we noticed that we're hitting the bug where inner objects are not inflated which is fixed by #26 but which has not been released on npm. Would you be able to push a new version to npm which includes this fix? Cheers

__datatype vs __typename

Hey, I'm a little confused... I've seen and used the __typename field but I can't get graphql-js to spit out a __datatype field. Also can't find it anywhere on google or the github repos for graphql or apollo. Plenty of __typename though :)

Where is this mystical __datatype documented?

Question about tradeoffs

I'm curious to know if a traditional compression method, like gzip, gives similar benefits? Or does this offer potential performance improvements on top of traditional compression? I'm not familiar with how those algorithms work, but would imagine they de-dupe? Or not?

Primitive values in an array

If you have a query that return an array of primitive values like [Float!]!, It still returns an empty object for each item in the array even after the fix in #21

To fix it I added this code to check if the node is neither an array or an object in both deflate and inflate functions

if (!Array.isArray(node) && !isObject(node)) { return node; }

Unable to minify with CRA 1.X

After taking a look at the built source code, you can see that arrow functions still exist in the output. This doesn't bode well for slightly older versions of uglify.

Would be great to consider adding an additional babel plugin to ensure that the artifacts can be safely minified.

Discussion: Alternative approach using normalized response

I developed a library to normalize/denormalize any graphql response which is available here: graphql-norm. If you want a more compact response, I guess normalizing it before returning it and then denormalizing on the client could be an alternative too or does graphql-deduplicator do some more tricks to cut the size down?

mongodb `ObjectId` gets transformed into JSON

When using with mongodb ObjectId, the field _id of type ObjectId gets transformed into JSON as follows:

{
    "0": 99,
    "1": 219,
    "2": 161,
    "3": 49,
    "4": 150,
    "5": 77,
    "6": 124,
    "7": 0,
    "8": 19,
    "9": 11,
    "10": 192,
    "11": 172
}

expected: I expect _id to be string equivalent! Otherwise there is overhead of converting these _id to hex string

Standard HTTP header to ask for deduplicated data

Instead of recommending to use a query param, why don't we recommend using a custom HTTP header to request deduplicated data?

  • inflate is a noop if the data wasn't deflated it doesn't matter whether the backend ends up sending deduplicated data or not
  • Headers aren't visible in the URL which is neater
  • Backend usage is the ~same

I imagine something like this:

const httpLink = new HttpLink({
  credentials: 'include',
  uri: '/api',
  headers: {
    'X-GraphQL-Deduplicate': true
  }
});
app.use('/graphql', graphqlExpress((request) => {
  return {
    formatResponse: (response) => {
      if (request.headers['X-GraphQL-Deduplicate'] && response.data && !response.data.__schema) {
        return deflate(response.data);
      }

      return response;
    }
  };
}));

Custom keyfields like Apollo InMemoryCache

I have some objects which don't use id as the key but some other fields and some objects where the id is not unique so I would like to disable de-duplication for them.

Is there a way to support a similar config as InMemoryCache to disable the de-duplication for them based on __typename?

Also Apollo supports both id and _id by default, can this module match the behaviour or atleast provide an option for default key name?

Conditional usage in Apollo Server

Any idea how I could use graphql-deduplicator conditionally in Apollo Server?

ApolloServer:formatResponse doesn't support access to the request object (or context) so I tried by doing a GraphQLExtension like this:

class DeduplicateResponseExtension extends GraphQLExtension<Context> {
  public willSendResponse(o: {
    graphqlResponse: GraphQLResponse;
    context: Context;
  }): { graphqlResponse: GraphQLResponse; context: Context } {
    const { context, graphqlResponse } = o
    if (context.req.query.deduplicate && graphqlResponse.data && !graphqlResponse.data.__schema) {
      const newResponse = deflate(graphqlResponse)
      return {
        ...o,
        graphqlResponse: newResponse,
      }
    }

    return o
  }
}

However, when using it I receive an error from Apollo Server:

{
  "error": {
    "errors": [
      {
        "message": "response.http.headers is not iterable",
        "extensions": {
          "code": "INTERNAL_SERVER_ERROR",
          "exception": {
            "stacktrace": [
              "TypeError: response.http.headers is not iterable",
              "    at [..]/node_modules/apollo-server-core/dist/runHttpQuery.js:164:55",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled ([..]/node_modules/apollo-server-core/dist/runHttpQuery.js:4:54)"
            ]
          }
        }
      }
    ]
  }
}

This issue might belong in apollo-server, asking here first to see if anyone knows of a setup that works with Apollo Server.

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.