Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
import Movies from '../collection.js';
// create fragments used to specify which information to query for
const moviesListProps = createFragment(gql`
fragment moviesListProps on Movie {
_id
name
createdAt
year
privateComments
user {
__displayName
}
}
`)
const moviesFullProps = createFragment(gql`
fragment moviesFullProps on Movie {
_id
name
// create fragments used to specify which information to query for
const moviesListProps = createFragment(gql`
fragment moviesListProps on Movie {
_id
name
createdAt
year
privateComments
user {
__displayName
}
}
`)
const moviesFullProps = createFragment(gql`
fragment moviesFullProps on Movie {
_id
name
createdAt
year
review
privateComments
user {
__displayName
}
}
`)
export { moviesListProps, moviesFullProps };
// create fragments used to specify which information to query for
const moviesListProps = createFragment(gql`
fragment moviesListProps on Movie {
_id
name
createdAt
year
privateComments
user {
__displayName
}
}
`)
const moviesFullProps = createFragment(gql`
fragment moviesFullProps on Movie {
_id
name
createdAt
year
review
privateComments
user {
__displayName
}
}
`)
export { moviesListProps, moviesFullProps };
it('correctly merges a query with inline fragments and passed fragments', (done) => {
const query = gql`
query peopleAndShips {
allPeople(first: 1) { ...Person }
allShips(first: 1) { ...ships }
}
fragment Person on PeopleConnection { people { name } }
`;
const shipFragment = createFragment(gql`
fragment ships on ShipsConnection { starships { name } }
`);
const mockedQuery = gql`
query peopleAndShips {
allPeople(first: 1) { ...Person }
allShips(first: 1) { ...ships }
}
fragment Person on PeopleConnection { people { name } }
fragment ships on ShipsConnection { starships { name } }
`;
const data = {
allPeople: { people: [ { name: 'Luke Skywalker' } ] },
allShips: { starships: [ { name: 'CR90 corvette' } ] },
};
it('should work with queries that use fragments', function(done) {
const query = gql`{ currentUser { ...userInfo } }`;
const userInfoFragment = createFragment(gql`fragment userInfo on User { firstName, lastName }`);
const data = { currentUser: { firstName: 'John', lastName: 'Smith' } };
const networkInterface = {
query: () => Promise.resolve({ data })
};
const apolloClient = new ApolloClient({ networkInterface });
const UserPage = graphql(query, {
options: {
fragments: userInfoFragment
}
})(({ data }) => (
<div>{data.loading ? 'Loading...' : `${data.currentUser.firstName} ${data.currentUser.lastName}`}</div>
));
const app = (
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
import Comments from 'meteor/nova:comments';
import Users from 'meteor/nova:users';
Comments.fragments = {
list: createFragment(gql`
fragment fullCommentInfo on Comment {
_id
postId
parentCommentId
topLevelCommentId
body
htmlBody
postedAt
user {
_id
__displayName
__emailHash
__slug
}
}
`/*, Users.fragments.avatar*/),
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
export const authUserDataFragment = createFragment(
gql`
fragment authUserData on AuthUser {
id
bio
email
name
avatar
public
role
}
`
);
export default authUserDataFragment;
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
import Comments from 'meteor/nova:comments';
import Users from 'meteor/nova:users';
Comments.fragments = {
list: createFragment(gql`
fragment fullCommentInfo on Comment {
_id
postId
parentCommentId
topLevelCommentId
body
htmlBody
postedAt
user {
_id
__displayName
__emailHash
__slug
}
}
`/*, Users.fragments.avatar*/),
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
const articleDataFragment = createFragment(
gql`
fragment articleDataFragment on Article {
title
status
content
json
spotlighted
featured
feature_image
tags {
id
tag
}
}
`
);
import { createFragment } from 'apollo-client';
import gql from 'graphql-tag';
export const authUserDataFragment = createFragment(
gql`
fragment authUserData on AuthUser {
id
bio
email
name
avatar
role
authToken: auth_token
}
`,
);
export default authUserDataFragment;