How to use the apollo-link.makePromise function in apollo-link

To help you get started, we’ve selected a few apollo-link 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 n1ru4l / graphql-schema-generator-rest / src / __tests__ / rest-link.js View on Github external
})

    const userProfileQuery = gql`
      query userProfile($id: ID!) {
        userProfile(id: $id)
          @rest(type: "User", route: "/users/:id", params: { id: $id }) {
          __typename
          id
          login
        }
      }
    `

    const link = createRestLink()

    const data = await makePromise(
      execute(link, {
        operationName: 'userProfile',
        query: userProfileQuery,
        variables: { id: '2' },
      }),
    )

    expect(data).toEqual({
      data: {
        userProfile: {
          __typename: 'User',
          id: '2',
          login: 'Jochen',
        },
      },
    })
github n1ru4l / graphql-schema-generator-rest / src / __tests__ / schema-link.js View on Github external
const query = gql`
      query user {
        user(id: "2") {
          __typename
          id
          login
          friends {
            id
            login
          }
        }
      }
    `

    const data = await makePromise(
      execute(link, {
        operationName: 'user',
        query: query,
      }),
    )

    expect(data).toEqual({
      data: {
        user: {
          __typename: 'User',
          id: '2',
          login: 'Jochen',
          friends: [
            {
              id: `1`,
              login: `Peter`,
github Rsullivan00 / apollo-link-json-api / src / __tests__ / jsonApiLink.ts View on Github external
fetchMock.post('/api/posts', {
        headers: { 'Content-Length': 0 },
        status: 500,
        body: post,
      });

      const createPostMutation = gql`
        mutation publishPost($input: PublishablePostInput!) {
          publishedPost(input: $input)
            @jsonapi(path: "/posts", method: "POST") {
            id
            title
          }
        }
      `;
      return await makePromise(
        execute(link, {
          operationName: 'publishPost',
          query: createPostMutation,
          variables: {
            input: {
              data: { type: 'posts', attributes: { title: post.title } },
            },
          },
        }),
      ).catch(e =>
        expect(e).toEqual(
          new Error('Response not successful: Received status code 500'),
        ),
      );
    });
  });
github n1ru4l / graphql-schema-generator-rest / src / __tests__ / rest-link.js View on Github external
expect.assertions(1)

    const userProfileQuery = gql`
      query userProfile($id: ID!) {
        userProfile(id: $id)
          @rest(type: "User", route: "/users/:id", params: { id: $id }) {
          __typename
          id
          login
        }
      }
    `

    const link = createRestLink()

    return makePromise(
      execute(link, {
        operationName: 'userProfile',
        query: userProfileQuery,
      }),
    ).catch(err => {
      expect(err.message).toEqual("Missing variable 'id'")
    })
  })
github theGlenn / apollo-prophecy / src / commands / ask / queryServer.ts View on Github external
function exeuteServerQuery(serverUri: string, type: string, headers: Headers) {
  const operation = makeOperation(type);
  const link = new HttpLink({ uri: serverUri, fetch, headers });

  return makePromise(execute(link, operation));
}
github apollographql / graphql-tools / src / stitching / linkToFetcher.ts View on Github external
return (fetcherOperation: FetcherOperation) => {
    return makePromise(execute(link, fetcherOperation as GraphQLRequest));
  };
}
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / upward-js / lib / resolvers / ServiceResolver.js View on Github external
headers,
            useGETForQueries: method === 'GET'
        });

        let parsedQuery;
        if (typeof query === 'string') {
            parsedQuery = new GraphQLDocument(query, this.visitor.io);
            await parsedQuery.compile();
        } else if (query instanceof GraphQLDocument) {
            parsedQuery = query;
        } else {
            throw new Error(`Unknown type passed to 'query'.`);
        }

        debug('running query with %o', variables);
        return makePromise(
            execute(link, { query: await parsedQuery.render(), variables })
        )
            .then(({ data, errors }) => {
                debug(
                    'query %s with %o resulted in %o',
                    definition.query,
                    variables,
                    { data, errors }
                );
                if (errors && errors.length > 0) {
                    throw new Error(errors[0].message);
                } else {
                    return { data };
                }
            })
            .catch(async e => {
github Sketch-sh / nit / server / auth / checkUserInfo.js View on Github external
}) => {
  const user_info = {
    id: user_id,
    email,
    name,
    username,
    avatar,
  };
  const user_identity = {
    identity_type: "github",
    identity_id: github_id,
    user_id,
    data,
  };

  return makePromise(
    execute(
      link,
      makeCreateGithubIdentityOperation({ user_info, user_identity })
    )
  );
};
github TallerWebSolutions / next-on-drupal / src / client / api / lib / introspection.js View on Github external
export const introspectLink = link =>
  introspectionData ||
  makePromise(execute(link, { query }))
    .then(normalize)
    .then(saveIntrospectionData)
    .catch(handleConnectionError)