on this page: • The Header component, which includes the following list of components: ProfileImage, BackgroundImage, TweetCount, FollowingCount, FollowersCount, LikesCount, and ListsCount • The Sidebar component, which includes the following list of components: UserInfo, FollowersYouKnow, UserMedia, and MediaItem. • The TweetList component, which is a list of Tweet components.
- an overview over the language 2. Apollo Client Installation, run queries and mutation in Angular 3. Mocking Test your application! What's the talk about?
tagline: String contributors: [User] } Ask for what you want { project(name: "GraphQL") { tagline } } Get predictable results { "project": { "tagline": "A query language for APIs" } }
versioning of your rest API. •Ask for what you need: Client has a provision to ask only those fields which they needs. There would be no handling on server side specific to the platform. •Get many API’s response in single request: Client has to call one query to get data from multiple rest API’s.
A signed double-precision floating-point value. • String: A UTF‐8 character sequence. •Boolean: true or false. • ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable. In most GraphQL service implementations, there is also a way to specify custom scalar types. For example, we could define a Date type: scalar Date
called Enums, enumeration types are a special kind of scalar that is restricted to a particular set of allowed values. • Validate that any arguments of this type are one of the allowed values • Communicate through the type system that a field will always be one of a finite set of values
} myField: [String!] myField: null // valid myField: [] // valid myField: ['a', 'b'] // valid myField: ['a', null, 'b'] // error myField: [String]! myField: null // error myField: [] // valid myField: ['a', 'b'] // valid myField: ['a', null, 'b'] // valid This means that the list itself can be null, but it can't have any null members This means that the list itself cannot be null, but it can contain null values
run: ng add apollo-angular If you want to setup Apollo without the help of Angular Schematics, just follow the few steps from the documentation: www.apollographql.com/docs/angular/basics/setup.html#without-schematics
can let you configure how queries are sent over HTTP, or replace the whole network part with something completely custom, like a websocket transport, mocked server data, or anything else you can imagine import { HttpClientModule } from '@angular/common/http'; import { ApolloModule, Apollo } from 'apollo-angular'; import { HttpLinkModule, HttpLink } from 'apollo-angular-link-http'; @NgModule({ imports: [ HttpClientModule, ApolloModule, HttpLinkModule ] }) class AppModule { constructor( apollo: Apollo, httpLink: HttpLink ) { const link = httpLink.create({ uri: 'https://example.com/graphql' }); apollo.create({ link, // other options like cache }); } }
made over the link and afterware runs after a request has been made, that is when a response is going to get processed @NgModule({ ... }) class AppModule { constructor( apollo: Apollo, httpLink: HttpLink ) { const http = httpLink.create({ uri: '/graphql' }); const authMiddleware = new ApolloLink((operation, forward) => { operation.setContext({ headers: new HttpHeaders() .set('Authorization', localStorage.getItem('token')) }); return forward(operation); }); apollo.create({ link: concat(authMiddleware, http), }); } }
in a simple, predictable way is one of the core features of Apollo Client 1.When the Query component mounts, Apollo Client creates an observable for our query. Our component subscribes to the result of the query via the Apollo Client cache. 2.First, we try to load the query result from the Apollo cache. If it’s not in there, we send the request to the server. 3.Once the data comes back, we normalize it and store it in the Apollo cache. Since the Query component subscribes to the result, it updates with the data reactively.
link execution chain errorPolicy "none" | "ignore" | "all" Specifies the ErrorPolicy to be used for this query fetchPolicy "cache-first" | "cache-and-network" | "network-only" | "cache-only" | "no-cache" | "standby" Specifies the FetchPolicy to be used for this query fetchResults any Whether or not to fetch results metadata any Arbitrary metadata stored in the store with this query. Designed for debugging, developer tools, etc. notifyOnNetworkStatusChange any Whether or not updates to the network status should trigger next on the observer of this query pollInterval any The time interval (in milliseconds) on which this query should be refetched from the server. query DocumentNode A GraphQL document that consists of a single query to be sent down to the server. variables TVariables A map going from variable name to variable value, where the variables are used within the GraphQL query.
the default value where we treat GraphQL errors as runtime errors. Apollo will discard any data that came back with the request and render your component with an error prop. • ignore: Much like none, this causes Apollo to ignore any data from your server, but it also won’t update your UI aside from setting the loading state back to false. • all: Selecting all means you want to be notified any time there are any GraphQL errors. It will render your component with any data from the request and any errors with their information. It is particularly helpful for server side rendering so your UI always shows something
The strongly-typed nature of a GraphQL API lends itself extremely well to mocking. import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools'; import { graphql } from 'graphql'; // Fill this in with the schema string const schemaString = `...`; // Make a GraphQL schema with no resolvers const schema = makeExecutableSchema({ typeDefs: schemaString }); // Add mocks, modifies schema in place addMockFunctionsToSchema({ schema }); const query = ` query tasksForUser { user(id: 6) { id, name } }`; graphql(schema, query).then((result) => console.log('Got result', result));
it’s an object that describes your desired mocking logic. This is similar to the resolverMap in makeExecutableSchema, but has a few extra features aimed at mocking. It allows you to specify functions that are called for specific types in the schema, for example: { Int: () => 6, Float: () => 22.1, String: () => 'Hello', } You can also use this to describe object types, and the fields can be functions too: { Person: () => ({ name: casual.name, age: () => casual.integer(0, 120), }), }
helpful for randomizing the number of entries returned in lists. { Person: () => ({ // a list of length between 2 and 6 (inclusive) friends: () => new MockList([2, 6]), // a list of three lists of two items: [[1, 1], [2, 2], [3, 3]] listOfLists: () => new MockList(3, () => new MockList(2)), }), } You can also use this to describe object types, and the fields can be functions too: { Person: () => ({ name: casual.name, age: () => casual.integer(0, 120), }), }