Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for @composeDirective #3

Merged
merged 25 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c8f5259
Add support for @composeDirective
utay Jun 14, 2023
2f19d5e
Use schema.join
utay Jun 15, 2023
66d060d
Lint, add links test
utay Jun 16, 2023
15cfca6
Merge pull request #1 from sorare/yu/compose-directive
utay Jun 16, 2023
ede329b
Add required to argument
utay Jun 16, 2023
96ec2ca
Drop minor version check
utay Aug 1, 2023
d373b7a
Make federation_2_prefix easier to read
utay Aug 1, 2023
0701bff
Lint
utay Aug 1, 2023
3cf158f
Add @policy and use federation_version in link
arutkowski00 Oct 31, 2024
8e41028
Improve ignores
arutkowski00 Oct 31, 2024
5ab53ba
Add policy directive
arutkowski00 Nov 13, 2024
cd90a71
Merge pull request #2 from mondaycom/feature/add-policy
arutkowski00 Nov 14, 2024
8911a18
Merge branch 'main' of github.com:sorare/apollo-federation-ruby into …
arutkowski00 Nov 14, 2024
27de46e
chore: create Github CI config
arutkowski00 Nov 14, 2024
e14052a
Upgrade rubocop, tweak rules & remove problematic package
arutkowski00 Nov 14, 2024
60dabf8
Fix tests
arutkowski00 Nov 19, 2024
af6265a
Don't run semantic release in PRs
arutkowski00 Nov 19, 2024
c278c90
Merge branch 'feature/github-ci' into feature/compose-directive
arutkowski00 Nov 20, 2024
e633d4e
Merge remote-tracking branch 'origin/main' into feature/compose-direc…
arutkowski00 Nov 20, 2024
1268834
Merge branch 'main' into feature/compose-directive
arutkowski00 Nov 20, 2024
0057d54
ci: split workflows
arutkowski00 Nov 20, 2024
b8d7d2f
delete semantic release notes (won't work)
arutkowski00 Nov 20, 2024
e4f5978
Check all links for imported directive
arutkowski00 Nov 20, 2024
4a497b8
Make functions public
arutkowski00 Nov 20, 2024
a59c8e0
Invert logic to satisfy RuboCop
arutkowski00 Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/semantic-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "Semantic PR Title"

on:
pull_request:
branches:
- main
types:
- opened
- edited
- synchronize
- reopened

permissions:
pull-requests: write

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

Details:

```
${{ steps.lint_pr_title.outputs.error_message }}
```

# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
116 changes: 0 additions & 116 deletions .github/workflows/semantic.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -100,8 +100,8 @@ def merge_directives(node, type)
end

def directive_name(directive)
if schema.federation_2? && !Schema::IMPORTED_DIRECTIVES.include?(directive[:name])
"#{schema.link_namespace}__#{directive[:name]}"
if schema.federation_2? && schema.all_links.none? { |link| link[:import]&.include?(directive[:name]) }
"#{schema.default_link_namespace}__#{directive[:name]}"
else
directive[:name]
end
55 changes: 45 additions & 10 deletions lib/apollo-federation/schema.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

module ApolloFederation
module Schema
IMPORTED_DIRECTIVES = ['inaccessible', 'policy', 'tag'].freeze
IMPORTED_DIRECTIVES = ['composeDirective', 'inaccessible', 'policy', 'tag'].freeze

def self.included(klass)
klass.extend(CommonMethods)
@@ -16,9 +16,11 @@ def self.included(klass)
module CommonMethods
DEFAULT_LINK_NAMESPACE = 'federation'

def federation(version: '1.0', link: {})
def federation(version: '1.0', default_link_namespace: nil, links: [], compose_directives: [])
@federation_version = version
@link = { as: DEFAULT_LINK_NAMESPACE }.merge(link)
@default_link_namespace = default_link_namespace
@links = links
@compose_directives = compose_directives
end

def federation_version
@@ -37,8 +39,8 @@ def federation_sdl(context: nil)
output
end

def link_namespace
@link ? @link[:as] : find_inherited_value(:link_namespace)
def default_link_namespace
@default_link_namespace || find_inherited_value(:default_link_namespace, DEFAULT_LINK_NAMESPACE)
end

def query(new_query_object = nil)
@@ -53,20 +55,53 @@ def query(new_query_object = nil)
federation_query_object
end

def compose_directives
@compose_directives || find_inherited_value(:compose_directives, [])
end

def links
@links || find_inherited_value(:links, [])
end

def all_links
imported_directives = IMPORTED_DIRECTIVES
default_link = {
url: "https://specs.apollo.dev/federation/v#{federation_version}",
import: imported_directives,
}
default_link[:as] = default_link_namespace if default_link_namespace != DEFAULT_LINK_NAMESPACE
[default_link, *links]
end

private

def original_query
@orig_query_object || find_inherited_value(:original_query)
end

def federation_2_prefix
federation_namespace = ", as: \"#{link_namespace}\"" if link_namespace != DEFAULT_LINK_NAMESPACE
schema = ['extend schema']

all_links.each do |link|
link_str = ' @link('
link_str += "url: \"#{link[:url]}\""
link_str += ", as: \"#{link[:as]}\"" if link[:as]
if link[:import]
imported_directives = link[:import].map { |d| "\"@#{d}\"" }.join(', ')
link_str += ", import: [#{imported_directives}]"
end
link_str += ')'
schema << link_str
end

compose_directives.each do |directive|
schema << " @composeDirective(name: \"@#{directive}\")"
end

<<~SCHEMA
extend schema
@link(url: "https://specs.apollo.dev/federation/v#{federation_version}"#{federation_namespace}, import: [#{(IMPORTED_DIRECTIVES.map { |directive| "\"@#{directive}\"" }).join(', ')}])
schema << ''
schema << ''

SCHEMA
schema.join("\n")
end

def schema_entities
Loading
Loading