VulcanJS / vulcan-docs

📖 Docs for React/Apollo/Meteor version of Vulcan
http://docs.vulcanjs.org
42 stars 88 forks source link

typo? in `schemas.md#resolveas` #19

Closed HaveF closed 7 years ago

HaveF commented 7 years ago

Thanks for making this repo:+1: I'm trying to go through all the doc.

In schemas.md#resolveas

  1. I did not get userId, maybe this should be User in Posts schema to correspond user in GraphQL schema?

    For example, you might have a userId(???User) property in your Posts schema, but want this property to resolve as a user object in your GraphQL schema (and in turn, in your client store). You can use resolveAs to accomplish this:

    resolveAs: 'user: User'
  2. The User and user confused me...The below means If I do not use resolveAs, but use GraphQLSchema.addSchema, all User property in Posts schema will convert to User as GraphQL type. Do I understand correctly?

    Note that in this case the User GraphQL type is generated automatically out of the box since Users(???User) is created using createCollection, but you could also add it manually:

    const userSchema = `
    type User {
    _id: String
    email: String
    ...
    }
    `;
    
    GraphQLSchema.addSchema(userSchema);
SachaG commented 7 years ago

No, it's not a typo. Here's the userId property in the posts schema:

  userId: {
    type: String,
    optional: true,
    control: "select",
    viewableBy: ['guests'],
    insertableBy: ['members'],
    hidden: true,
    resolveAs: 'user: User',
  }

So posts have a userId property that's a string. If you add resolveAs: 'user: User', in addition to that userId, posts will also have a user property that resolves as an object of type User.

If instead I wrote resolveAs: 'foo: Bar', I would have a foo property of type Bar. I hope that answers your question :)

HaveF commented 7 years ago

Wow! what a fast reply! Totally get the idea! Thanks!

HaveF commented 7 years ago

After reading your webpage, I become a fan of yours. 哈哈,我是来自中国的粉丝:smile: 希望我能学的更多,早日对这个项目有贡献

SachaG commented 7 years ago

欢迎!如果有什么问题,你也可以加入我们的Slack :)

http://slack.vulcanjs.org/