Comments (6)
This could be easily achieved by writing a Bramble plugin. The 'Init()' method on each plugin receives the schema so you can apply filtering rules and modify the schema in place that way. Happy to guide you through this if you want to contribute a PR.
from bramble.
Can you give me an hit about how to hide a field in with the Init
method by putting a directive (ex: @internal
) in my service's schema?
I tried few times, but couldn't get it to work yet. A little workable hint may help me get it.
Thank you @nmaquet!
from bramble.
I've had a closer look and unfortunately modifying the schema in the Init()
function isn't sufficient since the schema is rebuilt regularly. I think the only way to achieve this would be to add a new plugin method, something like AfterSchemaUpdate(schema *ast.Schema)
where the BasePlugin
implementation just does a no-op. To make this new plugin method work, you'll need to modify UpdateSchema
on ExecutableSchema
to call each plugin's AfterSchemaUpdate
method after the schema is updated (before the mutex Unlock()
).
Here's what the AfterSchemaUpdate
method could look like:
func (p *HidingPlugin) AfterSchemaUpate(schema *ast.Schema) {
if schema.Query != nil {
schema.Query.Fields = p.filterFieldList(schema.Query.Fields)
}
if schema.Mutation != nil {
schema.Mutation.Fields = p.filterFieldList(schema.Mutation.Fields)
}
if schema.Subscription != nil {
schema.Subscription.Fields = p.filterFieldList(schema.Subscription.Fields)
}
for _, t := range schema.Types {
t.Fields = p.filterFieldList(t.Fields)
}
for _, ts := range schema.PossibleTypes {
for _, t := range ts {
t.Fields = p.filterFieldList(t.Fields)
}
}
for _, ts := range schema.Implements {
for _, t := range ts {
t.Fields = p.filterFieldList(t.Fields)
}
}
}
func (p *HidingPlugin) filterFieldList(fields ast.FieldList) ast.FieldList {
result := ast.FieldList{}
for _, field := range fields {
if field.Directives.ForName("hidden") == nil {
result = append(result, field)
}
}
return result
}
from bramble.
An additional difficulty that I've forgotten to mention is that Bramble discards directives it doesn't know about. See https://github.com/movio/bramble/blob/main/merge.go#L226
If you want to keep your hidden
directive in the merged schema (required to do filtering) you'll have to either add the hidden
directive to the allowable directives in an hardcoded fashion (wouldn't be suitable for a PR unfortunately) or extend the plugin API to allow overriding the allowable directives list.
from bramble.
Can we add a new feature called scoped endpoint?
extend type Mutation {
blockUser(id: ID!) @boundary("/internal")
banUser(id: ID!) @boundary("/internal")
anotherMutation(id: ID!)
}
When, running the gateway, http://example.com/internal
will resolve all the queries,type,mutations loaded with @boundary("/internal")
directive?
Any other fields, queries, mutations will be available on http://example.com/query
.
What do you think? If it seems good, I can open another issue for this and close this one.
from bramble.
Hey @hsblhsn the change you're proposing is too big and not something we're interested in at this time. We're trying to keep Bramble simple and small and do one thing well. We're happy to consider extending Bramble's plugin API to accommodate more use cases, but we won't change the federation spec unless absolutely necessary. Closing this for now, let us know if you want to revisit a plugin-based approach as described above.
from bramble.
Related Issues (20)
- Request syntax error while trying to upload file HOT 5
- persisted queries HOT 1
- using Bramble as a library, add query/mutation resolvers in the gateway HOT 3
- Fragment not mapping fields for interface types HOT 7
- Lack of server timeouts HOT 1
- should bramble complain about built-in directives declared in spec? HOT 4
- Enabling/Disabling schema introspection HOT 6
- Types not used in any query are not getting into compiled schema? HOT 2
- Plugin` configuration doesnt depend on config changes HOT 3
- Differentiate log level depending on "response.status" HOT 4
- Schema being cached? HOT 1
- OperationPermissions dependent on type ID HOT 1
- Cannot access timings HOT 3
- nested abstract fragment error if returned type not queried HOT 5
- Bramble fails to read scheme HOT 2
- Rate limiters on Bramble? HOT 1
- Strict-Transport-Security on Bramble? HOT 1
- Add Datadog graphql trace HOT 8
- Config.json not loaded with docker volume HOT 1
- Allowed headers does not reach sub service HOT 3
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 bramble.