Skip to content

Instantly share code, notes, and snippets.

const query = `
{
search(text: "cat") {
text
id @instrument(tag: "search.id")
}
}
`;
import { GraphQLNonNull, GraphQLString } from 'graphql';
import { DirectiveLocation, GraphQLDirective } from 'graphql/type/directives';
const InstrumentDirective = new GraphQLDirective({
name: 'instrument',
description:
'Instrument the time it takes to resolve the field',
locations: [
DirectiveLocation.FIELD,
],
export default Relay.createContainer(StarWarsApp, {
fragments: {
factions: () => Relay.QL`
fragment on Faction @relay(plural: true) {
id,
factionId,
name,
ships(first: 10) {
edges {
node {
fragment on User @directiveBehavior {
id
}
query myQuery($someTest: Boolean) {
experimentalField @skip(if: $someTest)
}
const UserType = new GraphQLObjectType({
name : 'User',
interfaces: [SearchableType],
fields : {
// ...
},
isTypeOf: data => !!data.username;
});
const UserType = new GraphQLObjectType({
name : 'User',
interfaces: [SearchableType],
fields : {
username : {
type : GraphQLString
},
searchPreviewText : {
type : GraphQLString,
resolve(data) {
const schema = new GraphQLSchema({
types: [MovieType, BookType, UserType, SearchableType],
query: new GraphQLObjectType({
// ...
})
});
const SearchableType = new GraphQLInterfaceType({
name: 'Searchable',
fields: {
searchPreviewText: { type: GraphQLString }
},
resolveType: resolveType
});
const query = `
{
search(text: "cat") {
... on User {
username
}
... on Movie {
director
}
... on Book {