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 connections instead of array #435

Closed
Nutelac opened this issue Oct 7, 2015 · 5 comments
Closed

Use connections instead of array #435

Nutelac opened this issue Oct 7, 2015 · 5 comments
Labels

Comments

@Nutelac
Copy link

Nutelac commented Oct 7, 2015

First question: Is it good idea to use connections instead of array even when I don't need pagination (I need fetch all data all the time)? I want to do this thing because mutations performed with connections are easier than with arrays (e.g. creating or deleting).

Second question: How can I get all data from connections using Relay? When I do something like this in Relay fragment

fragment on User {
  roles {
    edges {
      node {
        ${Role.getFragment('role')}
      }
    }
  }
}

I'm getting error Error: Invariant Violation: readRelayQueryData(): The field 'roles' is a connection. Fields 'edges' and 'pageInfo' cannot be fetched without a 'first', 'last' or 'find' argument.. I know that I need pass some arguments to roles, but it's there any chance to get all data somehow?

@josephsavona
Copy link
Contributor

  1. How long is a typical array for this field?

  2. Relay doesn't provide a method to get all items in a connection; it's assumed that there will be a lot. You can use roles(first: $someLargeNumber) as a workaround to get all items.

@Nutelac
Copy link
Author

Nutelac commented Oct 7, 2015

  1. ~50 records.
  2. Thank you.

@wincent
Copy link
Contributor

wincent commented Oct 12, 2015

Hopefully you have enough information to answer your questions now, @Nutelac, so I'm going to close this. Feel free to comment again if you still have doubts.

I've published the content here over at Stack Overflow as it may prove useful to others in the future.

@wincent wincent closed this as completed Oct 12, 2015
@jvliwanag
Copy link

For getting all edges on a connection, the workaround is to choose a big number for first. Is this limitation something that can be fixed? Or is it here to stay?

@josephsavona
Copy link
Contributor

@jvliwanag This is an intentional restriction to prevent applications from fetching an entire connection with potentially thousands (or more) items. If you always plan to fetch all items a simple array may be more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants