polymer-apollo icon indicating copy to clipboard operation
polymer-apollo copied to clipboard

Automatically define property values as variables

Open bramvanderholst opened this issue 8 years ago • 1 comments

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>

bramvanderholst avatar Apr 14 '17 09:04 bramvanderholst

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

aruntk avatar Jul 06 '17 10:07 aruntk