Comments (8)
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.
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, andStarship
that always stays as-is). Is that what you mean? Or do you mean a custom resolver to the wholequery
? - 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.
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.
@neelance very interested in this feature. Any ETA ? Is there somewhere I could help ?
from graphql-go.
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.
I do not see this in the roadmap. Any progress or plan?
from graphql-go.
Any progress or plan?
from graphql-go.
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)
- Question on query string parsing HOT 1
- Rename types package
- Add enum example
- Allow directives without a Go visitor counterpart
- Allow field names starting with a leading `_`
- Allow struct fields which are functions
- Remove _service from the introspection and it should be opt-in
- Apollo Federation subgraph example
- The query resolver can't receive the context HOT 7
- `MustParseSchema` panics with nullable argument Directives HOT 6
- Subscription fails with missing method error HOT 1
- 2023/03/29 07:14:42 Error: The data source arguments are not valid HOT 3
- query parser bug HOT 1
- MongoDB _id field HOT 3
- Issue with negative numbers HOT 3
- Optimized batch loading without blocking HOT 2
- Please add simple example without react, relay, http etc... HOT 2
- [Bug] GraphQL server returns interface type for __typename when UseFieldResolvers is enabled HOT 1
- Directives import in example code seems wrong HOT 3
- New release with directive support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-go.