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

parts of fragments get ignored #365

Closed
u9520107 opened this issue Sep 22, 2015 · 11 comments
Closed

parts of fragments get ignored #365

u9520107 opened this issue Sep 22, 2015 · 11 comments

Comments

@u9520107
Copy link

I've got this strange issue where sometime part of a fragment would be missing from the actual query.

fragment on Viewer {
  id,
  user {
    id
  },
  categories {
    id,
    ...
  },
  products {
    ...
  }
}

Using react-router-relay for client-side route handling. When the page loads directly into this route, somehow the fragment composer would omit the categories portion, and only fetch back the user and products fields. But if the page initializes in a different route, then navigated to this route, then the query will be whole.

Where should I be looking first to track this problem?

@yuzhi
Copy link
Contributor

yuzhi commented Sep 22, 2015

The first place I would look at is the network tab on the browser to see if the query is being properly sent and if the server is returning reasonable payloads.
Can you check that first to see if you find anything useful?
I can suggest a few more places to look after you do that.
It might also be useful if you share more information about the specific route you have and the fragments in the component in question.

@u9520107
Copy link
Author

The query that was sent to server contains the portion with products, but not categories. This is by printing the raw text received on the server side.
So I think the error happens when Relay is gathering up fragments.
The strange thing is that products and categories are requested on the same fragment. Dunno why one of them goes missing.

@yuzhi
Copy link
Contributor

yuzhi commented Sep 22, 2015

Can you include more information about what your current route looks like and also what's defined on the schema for categories? Did you get any babel transform errors?

cc @josephsavona could this be printer related?

@u9520107
Copy link
Author

Type Category is basically like this.

type Category {
   id: globalIdField('Category'),
   tags: [GraphQLString],
   subCategories: [Category]
}

Type Viewer:

Type Viewer {
  id: globalIdField('Viewer'),
  products {
     type: ProductList    #sort of like connection with customized search features
  },
  productCategories {   #renamed to productCategories 
    type: [Category]
  }
}

Router setup:

<Router ...
>
  <Route
    path="/test"
    component={Test}
  />
  <Route
    path="/"
    component={App}
    queries={AppQueries}
  >
    <Route
      path="products"
      component={Products}
      queries={ProductsQueries}
    >
    </Route>
  </Route>
</Router>

App queries basically only viewer's id,
Product's fragments:

const Products = Relay.createContainer(ProductsView, {
  viewer: () => Relay.QL`
    fragment on Viewer {
      id,
      user {
        id
      },
      products {
        total,
        list {
          id,
          ...
         }
      },
      productCategories {
        id,
        subCategories {
          id
        }
      }
    }
  `,
});

There are no babel errors. In fact, if the page is loaded via '/test', then navigated to '/products', then the data fetch would be complete. ProductCategories is only missing when I try to access '/products' from the server directly.

@josephsavona
Copy link
Contributor

I understand that the productCategories field isn't sent to the server, but is the data for this field available in the component? Is this field queried anywhere else in the app, such that it might have already been cached?

@u9520107
Copy link
Author

@josephsavona This field would be undefined when the query's missing. This is the only place productCategories is used in a fragment.

@josephsavona
Copy link
Contributor

Ok, this is definitely weird. Can you produce a minimal repro case? The Relay playground would be perfect for this.

@u9520107
Copy link
Author

Ok... I can't seem to reproduce this on the Relay playground.

Our team has decided in favor of dropping relay for now, and rely on basic flux architecture, while using graphQL as the query language. So, my hands are pretty much tied at the moment.

I'll try to put together a repro case over the weekend.

@josephsavona
Copy link
Contributor

@u9520107 Yeah, a repro case would be great to have if possible. Thanks again for filing an issue!

@josephsavona
Copy link
Contributor

We have extensive tests that fields aren't removed from queries unless data exists in the cache. There isn't much we can do without a repro case - @u9520107, let us know if you're able to create one!

@u9520107
Copy link
Author

u9520107 commented Oct 7, 2015

Sorry, I am currently caught up on project schedules, and probably won't be able to work on this for a while. I'll try to create a repro case if I can squeeze out some time during next month.

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