aruntk / polymer-apollo

🚀 Polymer Apollo Integration
MIT License
78 stars 7 forks source link

Automatically define property values as variables #17

Open bramvanderholst opened 7 years ago

bramvanderholst commented 7 years ago

I have for example the following (simplified) element:

<script>
  Polymer({
    is: "rd-page-link",

    properties: {
      pageId: String,
      pageObject: Object
    },

    apollo: {
      PageLink: {
        query: Apollo.gql`query GetPageLink($identifier: ID!) {
                    pageObject: Page(id: $identifier) {
                      title,
                      urlKey
                    }
                  }`,
        options: '_queryOptions(pageId)',
      }
    },

    _queryOptions: function (pageId) {
      return {
        variables: {
          identifier: pageId
        },
      };
    },

  })
</script>

Wouldn't it be nice if you didn't have to define the link between the GraphQL variable $identifier and the polymer property pageId. Would be nice if the following just worked.

<script>
  Polymer({
    is: "rd-page-link",

    properties: {
      pageId: String,
      pageObject: Object
    },

    apollo: {
      PageLink: {
        query: Apollo.gql`query GetPageLink($pageId: ID!) {
                    pageObject: Page(id: $pageId) {
                      title,
                      urlKey
                    }
                  }`,
      }
    },

  })
</script>

And to move further, would be nice if we didn't need the key in the apollo object, doesn't serve any purpose?

<script>
  Polymer({
    is: "rd-page-link",

    properties: {
      pageId: String,
      pageObject: Object
    },

    apollo: [{
      query: Apollo.gql`query GetPageLink($pageId: ID!) {
            pageObject: Page(id: $pageId) {
              title,
              urlKey
            }
          }`,
    }],

  })
</script>
aruntk commented 7 years ago

@bramvanderholst Thanks for the feedback. :) . Added this in the pipeline.