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

global_id support #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

global_id support #128

wants to merge 2 commits into from

Conversation

alexeylightit
Copy link
Contributor

@alexeylightit alexeylightit commented Nov 6, 2019

Problem:
New tasks requires some knowing about full model type, while frontend can't know it, for example:
PossibleOutcome:

def transform_result_type
    self.result_type = "Perx::#{result_type.classify}::Entity"
end

Solution:
GlobalID uses different connections from Settings for each service to discover the model.
Benefits:

  • no need in type + id - gid field is enough
  • gid from the same service doesn't use any service-discovery objects - default models used instead

How to use:
Each Model, same as each Resource has :gid field.
ServiceLocator.locate(@model.gid)

Problem 2:
Frontend hardcode:

attributes: {
        amount: data.amount,
        start_date: data.start_date,
        source_type: 'Ros::Reward::Entity',
        source_id: data.source_id,
        code_type: data.code_type,
        code: data.code
}

Frontend solution:

attributes: {
        amount: data.amount,
        start_date: data.start_date,
        source: data.source_gid,
        code_type: data.code_type,
        code: data.code
}

Copy link
Contributor

@rpbaltazar rpbaltazar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I think that we can achieve this by using the URN instead of adding yet another attribute.
@alexeylightit what do you think?

@alexeylightit
Copy link
Contributor Author

alexeylightit commented Nov 12, 2019

As discussed, I think that we can achieve this by using the URN instead of adding yet another attribute.
@alexeylightit what do you think?

Since we use urn only inside jwt right now - I don't know if it's a good idea to invent a wheel instead of change urn to gid

@rpbaltazar
Copy link
Contributor

The urn is already part of the serialized attributes for all the records. The main advantage of the URN in comparison with the gid is that the urn has information about the tenant as well, so we can pinpoint exactly to the resource.

Since we are proposing a GlobalId Locator based on the gid wouldn't it behave the same if we rely on the urn instead?

"attributes": {
  "urn": "urn:whistler:loyalty::666666666:program/1",
  "created_at": "2019-11-19T02:23:04.506Z",
  "updated_at": "2019-11-19T02:23:04.506Z",
  "gid": "gid://loyalty/Program/1",
  "name": "Absolutely Loyal",
  "unit": "LoyalDolla",
  "status": "draft",
  "custom_tiers_count": 0
},

@rpbaltazar
Copy link
Contributor

To add to what i was saying, I think that this idea goes in line with rails/globalid#39 which is our usecase. I think it might be worth to explore as it would solve the problem of building a mapper between rails classes and readable attributes.

@alexeylightit
Copy link
Contributor Author

To add to what i was saying, I think that this idea goes in line with rails/globalid#39 which is our usecase. I think it might be worth to explore as it would solve the problem of building a mapper between rails classes and readable attributes.

It doesn't actually and I have working examples.

@alexeylightit
Copy link
Contributor Author

The urn is already part of the serialized attributes for all the records.

By the word 'using' I've ment we are doing something with this field. In other cases it's just exists

The main advantage of the URN in comparison with the gid is that the urn has information about
the tenant as well, so we can pinpoint exactly to the resource.

We don't need such information bc when we are calling any service-discovery model - it goes with default http request which already contains token. And this token has all the information we needed to reach the resource

Since we are proposing a GlobalId Locator based on the gid wouldn't it behave the same if we rely on the urn instead?

No it wouldn't. GlobalId Locator has it's own structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants