Coder Social home page Coder Social logo

Comments (8)

neelance avatar neelance commented on August 23, 2024

Hi @motiejus, I'm happy to hear that you find my project useful.

A solution that I can offer is a fully custom resolver, so you have full control on how a certain type gets resolved and which data it returns to the GraphQL client. I'm planning to implement that soon. However you'll not be able to only partially apply it to a type, it is either fully resolved by graphql-go or fully resolved by your custom code. Imho a catchall method does not fit into a clean implementation of the GraphQL spec, since any query for it would violate the schema (according to the spec).

Suggestion: Why don't you use a field like extendedPropery(name: String!): String!?

from graphql-go.

motiejus avatar motiejus commented on August 23, 2024

Hi Richard, thank you for a quick response; it's excellent that you are willing to implement this! Some remarks:

  • Re spec violation with catchall: whenever a new field gets added at runtime, I mean to regenerate schema and pass it down to the library. So from the client perspective, it would just be a new field. Only the resolver code would be a "catchall". Can you help me understand where is the schema violation?
  • I am really happy with the custom resolver, and, looking from your description, I think this is what I meant with "catchall". :) Just to be sure, it would be excellent if one could write some fields "the old way" with all fields known, and some fields with the custom resolver, in the query schema (e.g. in our StarWars example, that would be Character that might get a surname, and Starship that always stays as-is). Is that what you mean? Or do you mean a custom resolver to the whole query?
  • Re extendedPropery(name: String!): String!?: we currently have this, but this is a major pain point for our customers; we want to keep self-documenting GraphQL for dynamic fields too.

from graphql-go.

motiejus avatar motiejus commented on August 23, 2024

Hi again,

Since you proposed to implement this possibility, I thought it would be a good idea to express a way how I could use it, so you can reason about developer APIs more easily.

Inspired by your graphql meta-spec, I created an example repository to express and use a GraphQL schema in Thrift. I am sure you will find the thrift schema familiar.

Currently the example is using graphql-go/graphql, because it is possible to construct the GraphQL types and resolvers at runtime.

It would be cool to have a similar ability with your library.

Edit 2017-03-15: I had to remove the example repository, but, once you get to this task, I am happy to talk to you 1:1 and explain the approach.

from graphql-go.

hsyed avatar hsyed commented on August 23, 2024

@neelance very interested in this feature. Any ETA ? Is there somewhere I could help ?

from graphql-go.

hsyed avatar hsyed commented on August 23, 2024

I have had a look through the code.

Would supporting map[string]interface{} as a resolver be a clean solution ? One limitation though is that to pass state down the resolver chain closure functions would would be required for the fields or using the context somehow.

Alternatively, The following contract might be a good compromise ?

type CustomResolver interface {
	__ResolvesField__(ctx context.Context, name string) bool
	__Resolve__(ctx context.Context, name string, args map[string]interface{}) (interface{}, error)
}

from graphql-go.

wangyuheng avatar wangyuheng commented on August 23, 2024

I do not see this in the roadmap. Any progress or plan?

from graphql-go.

doucheng avatar doucheng commented on August 23, 2024

Any progress or plan?

from graphql-go.

pavelnikolov avatar pavelnikolov commented on August 23, 2024

There are no plans to add fields at runtime at this point. I'm closing this issue due to inactivity.

from graphql-go.

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.