smooth-code / fraql Goto Github PK
View Code? Open in Web Editor NEWGraphQL fragments made simple ⚡️
License: MIT License
GraphQL fragments made simple ⚡️
License: MIT License
When using fraql 1.1.1 with readFragment
it seems like the fragment in the graphql document cannot be found by apollo-client resulting in: Error: Found 0 fragments.
fragmentName must be provided when there is not exactly 1 fragment.
Using graphql-tag
works fine.
Let me know how I can help with investigation
There is the infamous react-native issue with react-native's Object.assign polyfill where this error is triggered when spreading anything with a prototype chain. https://github.com/facebook/react-native/blob/master/Libraries/polyfills/Object.es6.js#L48-L62.
It looks like other projects like apollo-client
avoid this (and get react-native compatibility) by using lodash assign.
Is this something you'd be open to?
This library looks awesome!
Is there any chance of Babel macro support for build-time compilation? This would make fraql a drop-in replacement for graphql.macro as well, for (performant) use with create-react-app.
This library is awesome, and I met a use case which are about the apollo variables.
I have more than two productByCode
fragments inside different components,
eg:
fragment on Query {
shop {
one: productByCode(codes: $codes) {
id
code
title
image
price {
amount
currencyCode
}
}
}
fragment on Query {
shop {
two: productByCode(codes: $codes) {
id
badge
image
}
}
How can inject the $codes
variables from the top, which can be got by different fragments.
Does the library support excluding some fields out of fragment ?
In my application, i generate fragments based on graphql schema, so it's a full-fields fragment.
In some cases, i just want to exclude some fields from generated fragments instead of duplicating it.
It's not real issue, but I'm wondering whats benefits fraql bring to development instead of simply doing this below with Vue?
// App.vue
<template lang="html">
<div class="apollo">
<div v-if="$apollo.loading">Loading...</div>
<div v-else-if="$apollo.error">Error :(</div>
<RateCard v-else v-for="rate in rates" :key="rate.currency" :rate="rate" />
</div>
</template>
<script>
import RateCard from './RateCard';
import gql from 'graphql-tag';
export default {
components: {
RateCard
},
apollo: {
rates: gql`{
rates(currency: "USD") {
${RateCard.fragments.rate}
}
}`,
},
data () {
return {
rates: '',
}
}
}
</script>
// RateCard.vue
<template>
<div style="margin: 20px">
<h2>{{rate.name}}</h2>
<p>
{{rate.currency}} - {{rate.rate}}
</p>
</div>
</template>
<script>
export default {
props: {
rate: Object
},
fragments: {
rate: `
name
currency
rate
`,
}
}
</script>
I'm just not using fraql :)
But my schema is closed to the template, and I can also pass variable to fragment and solve issue #10 !
Running apollo client:codegen --target typescript
from apollo-tooling
doesn't seem to pick up types from the fragment. Maybe this should be submitted in that repo but I was wondering if this is expected to work. Is this a static parsing issue? Can you think of any workarounds? Thanks 😃
Main component file:
import gql from 'fraql';
export const STEPS_QUERY = gql`
query StepsList($after: String) {
acceptedChallenges(after: $after, completed: false, first: 5) {
nodes {
id
focus
${STEP_ITEM_QUERY}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
}
`;
Child component file:
import gql from 'fraql';
export const STEP_ITEM_QUERY = gql`
fragment _ on AcceptedChallenge {
title
receiver {
id
fullName
}
}
`;
Generated types for main component:
/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: StepsList
// ====================================================
export interface StepsList_acceptedChallenges_nodes {
__typename: "AcceptedChallenge";
id: string;
focus: boolean;
}
export interface StepsList_acceptedChallenges_pageInfo {
__typename: "PageInfo";
/**
* When paginating forwards, the cursor to continue.
*/
endCursor: string | null;
/**
* When paginating forwards, are there more items?
*/
hasNextPage: boolean;
/**
* When paginating backwards, are there more items?
*/
hasPreviousPage: boolean;
/**
* When paginating backwards, the cursor to continue.
*/
startCursor: string | null;
}
export interface StepsList_acceptedChallenges {
__typename: "AcceptedChallengeConnection";
/**
* A list of nodes.
*/
nodes: (StepsList_acceptedChallenges_nodes | null)[] | null;
/**
* Information to aid in pagination.
*/
pageInfo: StepsList_acceptedChallenges_pageInfo;
}
export interface StepsList {
/**
* Find all accepted challenges for user
*/
acceptedChallenges: StepsList_acceptedChallenges;
}
export interface StepsListVariables {
after?: string | null;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.