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

Use virtualAttributes for GraphQL schema #44

Closed
timbaas opened this issue Feb 19, 2018 · 4 comments
Closed

Use virtualAttributes for GraphQL schema #44

timbaas opened this issue Feb 19, 2018 · 4 comments

Comments

@timbaas
Copy link

timbaas commented Feb 19, 2018

Hi there,

I can't find any way to get around the following.

I've got a Model ("Exchange") with a db column ("name") and a virtual attribute ("marketCount"):

class Exchange extends Model {
  static get tableName () {
    return 'exchanges';
  }
  
  static get virtualAttributes() {
    return ['marketCount'];
  }
  
  
  static get jsonSchema () {
    return {
      type: 'object',
      required: ['name'],
      properties: {
        id: {type: 'integer'},
        name: {type: 'string'},
        // marketCount: {type: 'number' }
      }
    };
  }
  
  marketCount () {
    return 1;
  }
}

When defining "marketCount" in jsonSchema properties it tries to select the column from the db, which of course doesn't exist and when leaving it out it isn't available in the GraphQL Schema, so the query fails.

I find it hard to believe this wouldn't be possible but didn't find the answer either.

Anything I don't know of?

@nasushkov
Copy link
Contributor

Hi @timbaas . This library utilizes Objection Model JSON schema to generate GraphQL fields. On the other hand, as you mentioned, if the field is a part of the schema it is supposed to exist in the db. So, virtual attributes are not supported yet, but I think it's worth implementing in the future.

@timhuff
Copy link
Collaborator

timhuff commented Jun 16, 2018

I just submitted a pull request which should facilitate this need: #55

@timhuff timhuff closed this as completed Jun 18, 2018
@DaKaZ
Copy link

DaKaZ commented Jul 9, 2019

@timhuff why was PR #55 reverted? Is there another way to handle virtual attributes?

@DaKaZ
Copy link

DaKaZ commented Jul 9, 2019

Ignore... I found PR #57

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

No branches or pull requests

4 participants