GithubHelp home page GithubHelp logo

Custom args builder about graphqlbundle HOT 5 CLOSED

overblog avatar overblog commented on May 29, 2024
Custom args builder

from graphqlbundle.

Comments (5)

mcg-web avatar mcg-web commented on May 29, 2024

Hi,

The relay ArgsBuilder or any other builder, can be combine with custom args. You must just add the args entry as you do when not using builder.

from graphqlbundle.

benatespina avatar benatespina commented on May 29, 2024

This is my concrete problem:

I'm trying to obtain a Foo collection resource that can be filtered by customFooArg and customFooArg2 but React Relay throws

Uncaught Error: Relay transform error Invalid root field foos; Relay only supports root fields with zero or one argument.
foos:
    type: "FooConnection"
    argsBuilder: ConnectionArgs
    args:
        customFooArg:
            description: "description of custom foo arg"
            type: "String"
        customFooArg2:
            description: "description of custom foo arg 2"
            type: "String"
import Relay from 'react-relay';
import RelayQuery from 'react-relay/lib/RelayQuery';
import RelayQueryRequest from 'react-relay/lib/RelayQueryRequest';

const query = Relay.QL`
  query {
    tasks(customFooArg: $customFooArg, customFooArg2: customFooArg2) {
      totalCount,
      edges {
        node {
          id
          description,
          customFooArg,
          customFooArg2
        }
        cursor
      }
      pageInfo {
        endCursor,
        hasNextPage
      }
    }
  }
`;

class FoosQueryRequest extends RelayQueryRequest {
  static build({customFooArg = null, customFooArg2 = null} = {}) {
    return new RelayQueryRequest(
      RelayQuery.Root.create(query, {}, {
        customFooArg,
        customFooArg2
      })
    );
  }
}

export default FoosQueryRequest;

from graphqlbundle.

mcg-web avatar mcg-web commented on May 29, 2024

It seems to be a relay limitation, i have try ConnectionArgs builder with one additional arg but never with more... in this issue it look like you must use an input object to bypass limitation.

#...
        fields:
            foos:
                 type: "FooConnection"
                 argsBuilder: ConnectionArgs
                 args:
                      customFooArgs:
                            description: "description of custom foo arg"
                            type: "CustomFooArgs"

CustomFooArgs:
    type: input-object
    config:
        fields:
            customFooArg:
                description: "description of custom foo arg"
                type: "String"
            customFooArg2:
                description: "description of custom foo arg 2"
                type: "String"

from graphqlbundle.

benatespina avatar benatespina commented on May 29, 2024

Yeah I solve the issue with input-object type, but I have put the connection arguments inside CustomFooArgs input object to avoid the limitation

from graphqlbundle.

mcg-web avatar mcg-web commented on May 29, 2024

Yeah that a nice news :) .

from graphqlbundle.

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.