-
-
Save blugavere/4060f4bf2f3d5b741c639977821a254f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
graphql, | |
} from 'graphql'; | |
import { | |
makeExecutableSchema, addResolveFunctionsToSchema, IResolverObject | |
} from 'graphql-tools'; | |
const types = ` | |
type Query { | |
person: User | |
} | |
type User { | |
id: ID | |
name: String, | |
dog(showCollar: Boolean): Dog | |
} | |
type Dog { | |
name: String | |
} | |
`; | |
const resolvers = { | |
Query: { | |
person(obj) { | |
console.log('Person Arg 1', obj); | |
return { | |
id: 'foo', | |
name: 'bar', | |
}; | |
} | |
} | |
}; | |
const schema = makeExecutableSchema({ | |
typeDefs: [types], | |
resolvers | |
}); | |
const User: IResolverObject = { | |
dog(obj, args, ctx) { | |
console.log('Dog Arg 1', obj); | |
return { | |
name: 'doggy' | |
}; | |
} | |
}; | |
addResolveFunctionsToSchema({ | |
schema, | |
resolvers: { | |
User | |
} | |
}); | |
const query = `{ | |
person { | |
name, | |
dog(showCollar: true) { | |
name | |
} | |
} | |
}`; | |
graphql(schema, query).then(result => { | |
console.log(JSON.stringify(result, null, 2)); | |
}); | |
// Person Arg 1 undefined | |
// Dog Arg 1 { id: 'foo', name: 'bar' } | |
// { | |
// "data": { | |
// "person": { | |
// "name": "bar", | |
// "dog": { | |
// "name": "doggy" | |
// } | |
// } | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment