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

Reusing a component #16

Closed
bramvanderholst opened this issue Mar 28, 2017 · 7 comments
Closed

Reusing a component #16

bramvanderholst opened this issue Mar 28, 2017 · 7 comments

Comments

@bramvanderholst
Copy link

Hi there,

I'm having trouble getting it to work properly, I have the following configuration for my element, seems pretty simple:

This binds the resulting object to the pageObject property of the element. This is great, but this seems me to require to name the query pageObject: Page(id: $identifier) { ... }. The result is that if I use this element multiple times, this will cause an issue that the the second element will use the same query name, thus breaking the first element..

Hope you can help:

  • I'm not exactly sure why I need to provide a name for the query in the first place, shouldn't the Apollo client handle this for me? It needs to batch multiple queries, etc...
  • The name of the first query object in the apollo object PageLink in this example serves no purpose at all, just needs to be unique (globally?). Ideally this would mean it would be bound to that property?
<dom-module id="rd-page-link">
  <template>
    <a href$="[[pageObject.urlKey]]"><content></content></a>
  </template>
  <script>
    Polymer({
      is: "rd-page-link",

      properties: {
        pageId: String,
        pageObject: Object,
        href: {
          type: String,
          computed: '_getHref(pageObject)'
        }
      },
      behaviors: [
        Apollo.PolymerBehavior,
      ],

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

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

      _getHref: function(pageObject) {
        console.log(pageObject);
        return pageObject.urlKey;
      },

    })
  </script>
</dom-module>
@paales
Copy link

paales commented Apr 4, 2017

@aruntk We're kind stuck on this part :( Idea how to solve this issue?

@aruntk
Copy link
Owner

aruntk commented Apr 4, 2017

@bramvanderholst @paales Issue is causing because of javascript object reference. I'm working on this.

@aruntk
Copy link
Owner

aruntk commented Apr 4, 2017

@bramvanderholst @paales. I think I have fixed the issue. version 1.1.21 released with the fix. Please check. I'm keeping the issue opened. Please comment if you find any other bugs related to the latest change.

@aruntk
Copy link
Owner

aruntk commented Apr 14, 2017

closing the issue. feel free to reopen if required.

@aruntk aruntk closed this as completed Apr 14, 2017
@bramvanderholst
Copy link
Author

bramvanderholst commented Apr 14, 2017

Hi @aruntk! It doesn't seem to work as expected. It does something different, but not what it is supposed to do..

I've created the following elements:

<rd-page-link page-id="Jaskdf021msksksv99ksdf"></rd-page-link> <!-- works -->
<rd-page-link page-id="cj0tns8lx1fus0104xxc1nbb4"></rd-page-link> <!-- works -->
<rd-page-link page-id="cj0tns8lx1fus0104xxc1nbb4"></rd-page-link> <!-- doesn't work -->
<rd-page-link page-id="cj0tns8lx1fus0104xxc1nbb4"></rd-page-link> <!-- doesn't work -->

So, if the query variables are exactly the same it doesn't work as expected..

@bramvanderholst
Copy link
Author

@aruntk I can't open the issue by the way ;)

@aruntk aruntk reopened this Apr 14, 2017
@bramvanderholst
Copy link
Author

@aruntk The above doesn't seem to apply. Random links don't seem to be working. I think it is some sort of race condition. If links are spaced out on the page (and thus probably in which tick they get called) it works, but if links are next to each other, it doesn't seem to work.

@aruntk aruntk closed this as completed in fb45e33 Jul 6, 2017
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

3 participants