Giter Club home page Giter Club logo

Comments (4)

Cito avatar Cito commented on June 2, 2024

I think the error message is corect. The tree of query_type.fields already includes the Query type, since it is referenced, so you can't define it again. This works, since you're using the same Query type:

GraphQLSchema(schema.get_type('Query'))

You can also remove the reference to the query type and then later add it again:

query = GraphQLObjectType('Query', {
    name: field for name, field in schema.query_type.fields.items()
    if name != 'relay'})
schema = GraphQLSchema(query)
schema.query_type.fields['relay!'] = GraphQLNonNull(query)

But I'm not sure what you actually want to achieve.

from graphql-core.

jdcaballerov avatar jdcaballerov commented on June 2, 2024

@Cito thanks for taking the time to answer. What I want to achieve that took me in this direction is a use case where I need to select, out of a big schema, just some subset of queries and mutations to obtain a smaller "scoped" schema. That's why I add the queries and mutations in that way.

I've been using a solution like the second one you propose, however, this gets complicated in some cases where the query type mentioned is nested. i.e

type Mutation {
 ....
  replaceTimeSeriesRange(
    """
    The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
    """
    input: ReplaceTimeSeriesRangeInput!
  ): ReplaceTimeSeriesRangePayload
....
}

  """All input for the `replaceTimeSeriesRange` mutation."""
input ReplaceTimeSeriesRangeInput {
  """
  An arbitrary string value with no semantic meaning. Will be included in the
  payload verbatim. May be used to track mutations by the client.
  """
  clientMutationId: String
  attributeOrTagId: BigInt
  entries: [TimeSeriesEntryInput]
  startTime: Datetime
  endTime: Datetime
}

"""The output of our `replaceTimeSeriesRange` mutation."""
type ReplaceTimeSeriesRangePayload {
  """
  The exact same `clientMutationId` that was provided in the mutation input,
  unchanged and unused. May be used by a client to track mutations.
  """
  clientMutationId: String
  json: JSON

  """
  Our root query field type. Allows us to run any query from our mutation payload.
  """
  query: Query
}

adding the mutation replaceTimeSeriesRange to a schema will raise the TypeError in a similar way.

from graphql-core.

Cito avatar Cito commented on June 2, 2024

Maybe have a look at the code of utilities.lexicographic_sort_schema and do it similary - instead of sorting fields, you would filter fields.

from graphql-core.

jdcaballerov avatar jdcaballerov commented on June 2, 2024

I'll need to check. Thanks for the hint. Closing since it's not a bug of the library.

from graphql-core.

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.