All Projects → Quramy → apollo-link-fragment-argument

Quramy / apollo-link-fragment-argument

Licence: MIT license
An Apollo Link to enable to parameterize fragments

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to apollo-link-fragment-argument

apollo-link-segment
Automatic analytics for Apollo Apps.
Stars: ✭ 18 (-48.57%)
Mutual labels:  apollo, apollo-link
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (+182.86%)
Mutual labels:  apollo, apollo-link
apollo-link-tracer
Trace your apollo queries and mutations with https://github.com/apollographql/apollo-link
Stars: ✭ 20 (-42.86%)
Mutual labels:  apollo, apollo-link
apollo-link-defer
Interface for creating asynchronous links.
Stars: ✭ 16 (-54.29%)
Mutual labels:  apollo, apollo-link
apollo-logger
Apollo GraphQL Logger
Stars: ✭ 19 (-45.71%)
Mutual labels:  apollo
graphqlizer
Make your meteor mongo collections accessible over a graphql endpoint
Stars: ✭ 37 (+5.71%)
Mutual labels:  apollo
rogue.js
The "nearly invisible" way to server-render React applications
Stars: ✭ 1,914 (+5368.57%)
Mutual labels:  apollo
GitHub-GraphQL-API-Example-iOS
An example iOS application using GitHub GraphQL API with Apollo.
Stars: ✭ 23 (-34.29%)
Mutual labels:  apollo
graphX
A simple blog based on Nuxt and graphQL
Stars: ✭ 19 (-45.71%)
Mutual labels:  apollo
react-apollo-mutation-state
A React HOC wrapper for Apollo GraphQL mutation, provides loading and error in props
Stars: ✭ 16 (-54.29%)
Mutual labels:  apollo
DiscoveryPlatform
☀️ Nepxion DiscoveryPlatform is a platform for Nepxion Discovery with service governance, release orchestration, flow inspection, instance blacklist, gateway route 服务治理、蓝绿灰度编排、流量侦测、实例摘除、网关路由的平台
Stars: ✭ 63 (+80%)
Mutual labels:  apollo
mern-apollo-graphql-boilerplate
MERN + Apollo-Graphql Boilerplate
Stars: ✭ 21 (-40%)
Mutual labels:  apollo
apollo-tracing-elixir
Apollo Tracing middleware for Absinthe
Stars: ✭ 114 (+225.71%)
Mutual labels:  apollo
kernel xiaomi sm8250
CLO Rebased kernel for Xiaomi SM8250 series devices updated to CAF tag LA.UM.9.12.r1-14700-SMxx50 with AOSP android-4.19-stable merged.
Stars: ✭ 111 (+217.14%)
Mutual labels:  apollo
apollo-express-ts-server-boilerplate
No description or website provided.
Stars: ✭ 29 (-17.14%)
Mutual labels:  apollo
swifters
Browse Swift users on GitHub
Stars: ✭ 13 (-62.86%)
Mutual labels:  apollo
agollo
🚀Go client for ctrip/apollo (https://github.com/apolloconfig/apollo)
Stars: ✭ 563 (+1508.57%)
Mutual labels:  apollo
create-full-stack
Set up a TypeScript full stack with one command.
Stars: ✭ 94 (+168.57%)
Mutual labels:  apollo
matnbaz
📚 The source-code for matnbaz.net. A monorepo containing the back-end (NestJS/Prisma/Apollo), front-end (Next.js/Apollo) and some tooling.
Stars: ✭ 481 (+1274.29%)
Mutual labels:  apollo
periqles
React form library for Relay and Apollo
Stars: ✭ 124 (+254.29%)
Mutual labels:  apollo

apollo-link-fragment-argument

npm

An Apollo Link to enable@argumentDefinitions and @arguments directives inspired from Relay Modern's Fragment container.

Usage

Install

$ npm i apollo-link-fragment-argument

Configure apollo client

import { ApolloClient } from "apollo-client";
import { InMemoryCache } from "apollo-cache-inmemory";
import { from } from "apollo-link";
import { createHttpLink } from "apollo-link-http";

import { createFragmentArgumentLink } from "apollo-link-fragment-argument";

function createApolloClient() {
  const cache = new InMemoryCache();
  const link = from([
    createFragmentArgumentLink(),
    createHttpLink({
      uri: "http://your.graphql.endpoint",
    }),
  ]);
  return new ApolloClient({
    cache,
    link,
  });
}

Using @argumentDefinitions and @arguments directive in your query

const todoListFragment = gql`
  fragment TodoList_list on TodoList
    @argumentDefinitions(
      count: { type: "Int", defaultValue: 10 } # Optional argument
      userID: { type: "ID" } # Required argument
    ) {
    title
    todoItems(userID: $userID, first: $count) {
      # Use fragment arguments here as variables
      ...TodoItem_item
    }
  }
`;
const query = gql`
  query TodoListQuery($count: Int, $userID: ID) {
    ...TodoList_list @arguments(count: $count, userID: $userID) # Pass arguments here
  }
  ${todoListFragment}
`;

Why?

I'm loving GraphQL's fragments colocation.

combined with GraphQL's support for fragments, allows you to split your queries up in such a way that the various fields fetched by the queries are located right alongside the code that uses the field.

However, GraphQL syntax has no ability to parameterize Fragment (See graphql/graphql-spec#204 if you want detail).

@argumentDefinitions and @arguments are originally introduced by Relay Modern to compose parametrized Fragments. See https://relay.dev/docs/en/fragment-container.html#composing-fragments ,

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].