GithubHelp home page GithubHelp logo

graphql-kit / graphql-lodash Goto Github PK

View Code? Open in Web Editor NEW
1.2K 16.0 50.0 5.8 MB

๐Ÿ›  Data manipulation for GraphQL queries with lodash syntax

Home Page: https://apis.guru/graphql-lodash/

License: MIT License

TypeScript 96.08% JavaScript 3.92%
graphql functional-programming api lodash

graphql-lodash's People

Contributors

0xflotus avatar ivangoncharov avatar mattleff avatar nisaacson avatar romanhotsiy avatar vedmalex 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-lodash's Issues

express-graphql / graphqlHTTP implementation example

Thank you for you great job - I was looking to implement the server version on the express-graphql stack here is my implementation as an example - not perfect but works:

     // schema is the initial schema you wanted to deploy

     schema = extendSchema(
      schema,
      lodashDirectiveAST,
    );

    app.use('/graphql', (...args) => {

      graphqlHTTP({
        schema: schema,
        graphiql: true,
        customParseFn : (source) => {

          // get the query from the body
          let body = source.body;

          // Process the lodash parsing
          let { query, transform } = graphqlLodash(body);

          // Replace the body in the Source instance
          source.body = query;

          // Use the standard parse method
          let documentAST = graphql.parse(source);

          // store the transform in the document, an element conveyed in customExecuteFn
          documentAST.transform = transform;

          return documentAST;

        },
        customExecuteFn : async ( { document, ...args } ) => {

          // Execut first
          let result = await graphql.execute( { document: document, ...args });

          // Then back transform the query.
          result.data = document.transform(result.data);

          // Return the result
          return result;

        }
      })(...args);

    });

  • cheers -

The Headers buttons don't do anything

In the GraphiQL demo, the [Add] button under the headers does nothing:

image

I would like to use this to submit some authentication headers to my query, but I can't.

do not works with array of strings

the query

{
  Films: allFilms(first:1) @_(get:"films"){
    films {
      title
      producers @_(join:",")
    }
  }
}

returns

{
  "data": {
    "Films": [
      {
        "title": "A New Hope",
        "producers": "[object Object],[object Object]"
      }
    ]
  }
}

instead of

{
  "data": {
    "Films": [
      {
        "title": "A New Hope",
        "producers": "Gary Kurtz,Rick McCallum"
      }
    ]
  }
}

missing functionality to flatten array

I have the following query:

movie {
  cast {
    id
    role
    person {
      actorId: id
      fullName
    }
  }
}

Now I would like to flatten the cast into an array of not-nested objects.

movie {
  cast {
    id
    role
    actorId
    fullName
  }
}

It seems like lodash can't do that. Would be nice to add a functionality, maybe like:

movie {
  cast @_(flattenObjectDepth: 1) {
    id
    role
    person {
      actorId: id
      fullName
    }
  }ย 
}

I could create a PR, with a little help as to how transformations need to look like.

Usage with "GraphQL Code Generator"

Hi, this plugin it's awesome! I'm able to get it working with @apollo/client with a custom ApolloLink as suggested in documentation.

It's also possible to make GraphQL Code Generator generate right types? I'm using it to generate Typescript types and React Hooks.

typescript-operations is the plugin that generate types, maybe should be possible to pass graphql-lodash custom directives and use them to generate right the types.

Some advice on how to do it?

Is it really possible to flatten the data with some duplication?

I have a data structure like below

{
"MyAsset": {
"Code": "Cod123",
"MyAssetLocation": [{
"Location": {
"LocationName": "Location 1"
}
},{
"Location": {
"LocationName": "Location 2"
}
}
]
}
}
I wanted to write a graphql query against the entity MyAsset in such a way that it should return the data like below.

First record

{code:"Cod123",MyAssetLocation.Location:"Location 1"}
Second Record

{code:"Cod123",MyAssetLocation.Location:"Location 2"}
Basically I wanted to flatten the result by duplicating MyAsset details with MyAssetLocation.Location Items.

enable type casting

One of the very common transformations I need (except from the ones that this library already enables) is casting a value into a Date. Would it be possible to add a function for that like:

movie {
  title
  releaseDate @_(as: "Date")
}

Is it possible to reverse the transformation process?

Hi,

I just get started learning Graphql and found this package extremely useful for formatting data reading from backend. Thank you!

My question is that is is possible to reverse the transformation process without manually manipulating the object? I'm asking because when I followed the Apollo Documentation (https://www.apollographql.com/docs/react/essentials/mutations/#making-all-other-cache-updates) to implement cache updating using useMutation to create a new object. The newly created object needs to be concatenated to the list of old objects in order to update the cache.

So far I can use graphqlLodash to get back the query (readable to the Apollo client) and use cache.readQuery to get back the DATA (before formatting by graphql-lodash), but it seems not that easy to format the newly created object into the same format of that DATA before I can concat them to update my list of objects.

If there's another way to work around it. Please let me know! Really appreciate that!

Thank you,
Changsheng

Add more examples?

Thanks for this awesome library but I would love to see some more examples. What I see in the code there is more operators that you added but they are not documented.

Server side usage - seems to be working well :-)

Thanks for this library, it's really cool!

You mention this will break the contract and, most likely, will break all the GraphQL tooling you use but I don't really understand why - could you elaborate?

I've experimented a bit in a pet project and I have had no problems with it so far :-)

Regards

Apollo - Angular Example

That's really such a great idea! Do you have already experience with Apollo - Angular integration?
If you have an example it would be really great to see it :)

Change demo to move away from anachronistic gender terminology

Hi, I'm a developer advocate and came across this project (it's a great project!). I'd like to politely suggest either modernizing the gender data used in the tool demo, or simply demonstrating queries on a different dataset.

image

Genderkit is one of many resources helping content producers talk about gender in a modern, ethical way. Almost all such resources recognize "hermaphrodite" as an offensive term. While the usage in this project is only sample data in a query, I would strongly appreciate if you'd change the data source, or remove this offensive term and also use a data-set that does not reflect a male/female binary. Thank you! ๐Ÿ™

Mocking graphqlLodash with Jest

Hello,

First of all, thanks for the nice project.
I am trying to mock graphql-lodash with Jest, in order to test components decorated with it.
Is there any de-facto / preferred way of mocking it? Below I add my code snippets.

Tests:

import React from 'react';
import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
import chaiEnzyme from 'chai-enzyme';

import Foo from './Foo';

describe('Foo', () => {
  const shallowed = shallow(<Foo />);

  it('test Foo', () => {
   {...}
  });
});

chai.use(chaiEnzyme());

I have tried multiple ways to mock, but i keep on getting errors.

Thanks ๐Ÿ™‚

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.