Giter Site home page Giter Site logo

Comments (6)

nmaquet avatar nmaquet commented on May 16, 2024

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.

hsblhsn avatar hsblhsn commented on May 16, 2024

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.

nmaquet avatar nmaquet commented on May 16, 2024

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.

nmaquet avatar nmaquet commented on May 16, 2024

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.

hsblhsn avatar hsblhsn commented on May 16, 2024

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.

nmaquet avatar nmaquet commented on May 16, 2024

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)

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.