How to use the apollo-client.createFragment function in apollo-client

To help you get started, we’ve selected a few apollo-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LessWrong2 / Lesswrong2 / packages / custom-collection-demo / lib / containers / fragments.js View on Github external
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
github VulcanJS / Vulcan / packages / custom-collection-demo / lib / containers / fragments.js View on Github external
// 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 };
github LessWrong2 / Lesswrong2 / packages / custom-collection-demo / lib / containers / fragments.js View on Github external
// 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 };
github apollographql / react-apollo / test / react-web / client / graphql / fragments.tsx View on Github external
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' } ] },
    };
github apollographql / react-apollo / test / react-web / server / index.tsx View on Github external
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 = (
github VulcanJS / Vulcan / packages / nova-base-containers / lib / fragments / comments.js View on Github external
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*/),
github udacityalumni / udacity-alumni-fe / app / src / containers / UserProfileContainer / graph / authUserDataFragment.js View on Github external
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;
github LessWrong2 / Lesswrong2 / packages / nova-base-containers / lib / fragments / comments.js View on Github external
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*/),
github udacityalumni / udacity-alumni-fe / app / src / containers / CmsEditorContainer / graph / fragments.js View on Github external
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
      }
    }
  `
);
github RyanCCollins / ryancollinsio / client / app / src / fragments / authUserDataFragment.js View on Github external
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;