Skip to content

Commit

Permalink
Merge branch 'master' into support-wrap-query-selection-set-return
Browse files Browse the repository at this point in the history
  • Loading branch information
stubailo authored Jul 31, 2018
2 parents e5d71f4 + 456555f commit b1cc8da
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/resolvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ These arguments have the following meanings and conventional names:

1. `obj`: The object that contains the result returned from the resolver on the parent field, or, in the case of a top-level `Query` field, the `rootValue` passed from the [server configuration](/docs/apollo-server/setup.html). This argument enables the nested nature of GraphQL queries.
2. `args`: An object with the arguments passed into the field in the query. For example, if the field was called with `author(name: "Ada")`, the `args` object would be: `{ "name": "Ada" }`.
3. `context`: This is an object shared by all resolvers in a particular query, and is used to contain per-request state, including authentication information, dataloader instances, and anything else that should be taken into account when resolving the query. If you're using Apollo Server, [read about how to set the context in the setup documentation](/docs/apollo-server/setup.html).
3. `context`: This is an object shared by all resolvers in a particular query, and is used to contain per-request state, including authentication information, dataloader instances, and anything else that should be taken into account when resolving the query. If you're using Apollo Server, [read about how to set the context in the setup documentation](/docs/apollo-server/essentials/data.html#context).
4. `info`: This argument should only be used in advanced cases, but it contains information about the execution state of the query, including the field name, path to the field from the root, and more. It's only documented in the [GraphQL.js source code](https://github.com/graphql/graphql-js/blob/c82ff68f52722c20f10da69c9e50a030a1f218ae/src/type/definition.js#L489-L500).

### Resolver result format
Expand Down
2 changes: 1 addition & 1 deletion docs/source/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const resolvers = {
Query: {
favoriteColor: () => 'RED',
avatar: (root, args) => {
// args.favoriteColor is 'RED', 'GREEN', or 'BLUE'
// args.borderColor is 'RED', 'GREEN', or 'BLUE'
},
}
};
Expand Down
2 changes: 1 addition & 1 deletion docs/source/schema-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const schema = makeExecutableSchema({
});
```

Of course, it would be even better if the schema author did not have decide on a specific `Date` format, but could instead leave that decision to the client. To make this work, the directive just needs to add an additional argument to the field:
Of course, it would be even better if the schema author did not have to decide on a specific `Date` format, but could instead leave that decision to the client. To make this work, the directive just needs to add an additional argument to the field:

```js
import formatDate from "dateformat";
Expand Down
2 changes: 1 addition & 1 deletion docs/source/schema-stitching.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ resolvers: {
property: {
fragment: '... on Booking { propertyId }',
resolve(parent, args, context, info) {
return mergeInfo.delegateToSchema({
return info.mergeInfo.delegateToSchema({
schema: bookingSchema,
operation: 'query',
fieldName: 'propertyById',
Expand Down
3 changes: 3 additions & 0 deletions src/generate/addResolveFunctionsToSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function addResolveFunctionsToSchema(

if (type instanceof GraphQLEnumType) {
if (!type.getValue(fieldName)) {
if (allowResolversNotInSchema) {
return;
}
throw new SchemaError(
`${typeName}.${fieldName} was defined in resolvers, but enum is not in schema`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLEnumType,
Expand All @@ -13,7 +14,6 @@ import {
GraphQLNamedType,
GraphQLFieldResolver,
} from 'graphql';
import { graphql } from 'graphql';
import * as uuid from 'uuid';
import {
forEachField,
Expand Down
2 changes: 1 addition & 1 deletion src/stitching/delegateToSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import CheckResultAndHandleErrors from '../transforms/CheckResultAndHandleErrors

export default function delegateToSchema(
options: IDelegateToSchemaOptions | GraphQLSchema,
...args: any[],
...args: any[]
): Promise<any> {
if (options instanceof GraphQLSchema) {
throw new Error(
Expand Down
45 changes: 45 additions & 0 deletions src/test/testSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,51 @@ describe('generating schema from shorthand', () => {
).to.not.throw();
});

it('does not let you define resolver field for enum values not present in schema', () => {
const short = `
enum Color {
RED
}
enum NumericEnum {
TEST
}
schema {
query: Query
}
type Query {
color: Color
numericEnum: NumericEnum
}
`;

const rf = {
Color: {
RED: '#EA3232',
NO_RESOLVER: '#EA3232',
},
NumericEnum: {
TEST: 1,
},
};

expect(() =>
makeExecutableSchema({ typeDefs: short, resolvers: rf }),
).to.throw(`Color.NO_RESOLVER was defined in resolvers, but enum is not in schema`);

expect(() =>
makeExecutableSchema({
typeDefs: short,
resolvers: rf,
resolverValidationOptions: {
allowResolversNotInSchema: true,
},
}),
).to.not.throw();
});

it('throws if conflicting validation options are passed', () => {
const typeDefs = `
type Bird {
Expand Down

0 comments on commit b1cc8da

Please sign in to comment.